Google Sheets – Handle Negative Time Delta

google sheets

If I have two cells, one is the starting time and one is the ending time. How do I calculate the time difference if the end time is in the next day?

= B1 - A1 gives a negative time.

=IF(B1-A1, B1-A1, B1+24/24-A1) always evaluates the test expression to be true. Otherwise I think it will work.

Any ideas how to solve this?

---------------------------------
|   A           |   B           |
---------------------------------
|   9:30:00 PM  |   12:15:00 AM |
---------------------------------

Best Answer

The handy little cheat:

=MOD(B1-A1,1)

but more intuitive:

=IF((B1-A1)>=0,B1-A1,1+B1-A1)

but that can be simplified to:

=(B1-A1)+((B1-A1)<0)