Reputation: 159
I have a series of times and I am trying to find the difference in time between two values which is fine for a normal day however some times pass midnight e.g.
18:00 - 00:30
The time difference is 6 hours 30 minutes which I would like returned in a numerical value e.g. 6.5 hours. However whenever I pass midnight it is not calculating properly.
Is there anyway to work around this without having to input the dates on each value? I would like it to assume if I am between the hours of 00:00 & 08:00 then I mean the following morning and anything between 08:01 and 23:59 is from the previous day.
Upvotes: 0
Views: 328
Reputation: 152505
Use this formula:
=IF(A1>B1,1,0)+B1-A1
To get the 6.5
just multiply by 24, and make the format general:
=(IF(A1>B1,1,0)+B1-A1)*24
Edit #2
We can get rid of the IF as the expression (A1>B1)
will return 1/0.
=((A1>B1)+B1-A1)*24
Upvotes: 4
Reputation:
Try it as,
=ABS(SUM(A2, -(B2+(B2<TIME(8, 0, 0)))))*24
... which leaves 6.5
as 6 (integer) representing hours and .5 (decimal) representing 30 minutes.
Upvotes: 3