Doing this with formulas is somewhat painful, so I've used LET to hopefully make it easier to read. It would be much easier to use PowerQuery, but I think this will work. If you have access to LAMBDA
, which unfortunately I don't, I recommend using that.
First of all, I've defined the start/end separator, i.e. " - ", as a Named Cell called "sep" in cell B2:

I've done that so if you want to change it to "-" or something else in the future, you won't have to change it in several places in formulas, but rather just in that one cell.
With Helper Columns for Start and End
The approach here is broadly:
- determine the position of the separator in the string and call that "pos"
- return the time as text and call it "str"
- determine if the time as text contains minutes (indicated by presence of a colon) and call that "hasmin"
- calculate the time representation of "str", which is modified from the original answer you used, but taking different action depending on whether "hasmin" is TRUE or not
Start time formula in B3:
=LET(pos,FIND(sep,$A3),
str,LEFT($A3,pos1),
hasmin,NOT(ISERROR(FIND(":",str))),
TIME(LEFT(str,IF(hasmin,FIND(":",str)-1,LEN(str)-2))+IF(RIGHT(str,2)="pm",12,0),IF(hasmin,MID(str,FIND(":",str)+1,2),0),0))
End time formula in C3:
=LET(pos,FIND(sep,A3),
str,MID(A3,pos+LEN(sep),LEN(A3)),
hasmin,NOT(ISERROR(FIND(":",str))),
TIME(LEFT(str,IF(hasmin,FIND(":",str)-1,LEN(str)-2))+IF(RIGHT(str,2)="pm",12,0),IF(hasmin,MID(str,FIND(":",str)+1,2),0),0))
Hours elapsed formula in D3:
=IF(C3>B3,C3-B3,C3+1-B3)*24
As a single formula
Here I have just combined the two "Start Time" and "End Time" columns into the same LET
, calling them "from_time" and "to_time". The last expression, i.e. the result, is then just the formula in the "Hours elapsed" column, but referring to the names in the LET
function instead of the columns.
In E3:
=LET(break_pos,FIND(sep,$A3),
from_text,LEFT($A3,break_pos-1),
from_has_mins,NOT(ISERROR(FIND(":",from_text))),
from_time,TIME(LEFT(from_text,IF(from_has_mins,FIND(":",from_text)-1,LEN(from_text)-2))+IF(RIGHT(from_text,2)="pm",12,0),IF(from_has_mins,MID(from_text,FIND(":",from_text)+1,2),0),0),
to_text,MID($A3,break_pos+LEN(sep),LEN($A3)),
to_has_mins,NOT(ISERROR(FIND(":",to_text))),
to_time,TIME(LEFT(to_text,IF(to_has_mins,FIND(":",to_text)-1,LEN(to_text)-2))+IF(RIGHT(to_text,2)="pm",12,0),IF(to_has_mins,MID(to_text,FIND(":",to_text)+1,2),0),0),
IF(to_time>from_time,to_time-from_time,to_time+1-from_time)*24
)