How to subtract time difference and add 24 hours if time is after midnight?

helpneeded2

Board Regular
Joined
Jun 25, 2021
Messages
110
Office Version
  1. 365
Platform
  1. Windows
I have a sheet that has a column for an Arrival Time (column E) and a Departure Time (column F). If the Departure time is after midnight, then it will never be later than 4:00am. The Arrival time will never be earlier than 8:00am.

I want the sheet to show the time difference.

I thought this formula might do it, but it errors out when the time is greater than midnight.

Excel Formula:
=IF(AND(HOUR(F3)>=0,HOUR(F3)<5),F3+TIME(24,0,0),F3)-E3

Can anyone please suggest a tweak I can do to make this work?
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Do you want something like this?


Book3
EFG
1ArriavalDepartureDifference
24:008:004:00
311:00 PM8:009:00
4
Sheet1
Cell Formulas
RangeFormula
G2:G3G2=F2-E2+(F2<E2)
 
Upvote 0
MrExcelPlayground7.xlsx
GHI
2014:003:1513:15
218:0016:308:30
Sheet1
Cell Formulas
RangeFormula
I20:I21I20=IF(H20<=4/24,H20+1-G20,H20-G20)
 
Upvote 0
Try it like
Excel Formula:
=IF(AND(HOUR(F3)>=0,HOUR(F3)<5),F3+1,F3)-E3
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,225,288
Messages
6,184,085
Members
453,211
Latest member
tuantcdn

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top