Round Excel Time Difference to Next 15 Minute Interval - excel

I have a start time and an End Time in Excel:
Start Time
9:15 PM
End Time 9:30 PM
Time Spent 0:15
I'm looking to round up to the next 15 minute increment, and are using the formula:
=ROUNDUP(A1*96,0)/96
However, this rounds up the example data above from 0:15 to 0:30 (It should stay at 0:15 because it's a quarter hour already)
How to I avoid the rounding if the time difference is ALREADY on a quarter hour?

I would normally expect the original formula to work. When I test in Excel 2007 with manually input time values that are always whole minutes the original formula with ROUNDUP, brettdj's formula and the following formula:
=CEILING(A1,"0:15")
.....all give me the same results
....but if the times are derived from some sort of formula calculation then excel floating point arithmetic can cause very small rounding errors so that 0:15 is deemed to be very marginally above that value (although it would still display as 0:15:00.000) and is therefore rounded up to 0:30.
Because brettdj's suggestion only looks at hours and minutes that problem is avoided but it will round 0:15:59 to 0:15 too, so this approach might be preferable
=CEILING(MROUND(A1,"0:0:01"),"0:15")
That rounds the original time to the nearest second with MROUND (thus dealing with any floating point errors) and then rounds up to the next quarter hour
Edit: if you are using a formula to get the A1 time value it might be worth incorporating some rounding within that formula, e.g. wrap formula in MROUND like this to round to the nearest second
=MROUND(formula,"0:0:01")
It may look like that does nothing in terms of changing the formula results but that will potentially avoid any further floating point issues with any other calculations you might need to do.....and then your original formula with ROUNDUP should work......

You could use
=HOUR(A1)/24+CEILING(MINUTE(A1),15)/(24*60)
which converts a time in A1 of
- 9:15 PM to 9:15 PM
- 9:16 PM to 9:30 PM
etc

Related

Excel IF AND formula between two times

I would like to have a formula which will tell me if a time in a cell is between 2 separate vlaues in other cells and to return a value if so.
I have already created the below code but this is not returning any values back at all.
=IF(AND(F4>=$R$1,F4<P1),"Night Shift",IF(AND(F4>=$P$1,F4<$Q$1),"AM Shift",IF(AND(F4>=$Q$1,F4<$R$1),"PM Shift","")))
In this example the cell values are (P1 = 06:00, Q1 = 14:00, R1 = 22:00). The value in the F4 is 00:31:38.
Any help would be appreciated.
Your first AND needs to adjust a little.
Excel sees TIME as a fraction of 1 whole day. So 00:31:38 though you meant it to be the next day from 22:00, Excel does not know that and as such will not see it greater than 22:00
We also do not need to test for the Night Shift. It is the only option left if the time is not in one of the others:
=IF(F4<>"",IF(AND(F4>=$P$1,F4<$Q$1),"AM Shift",IF(AND(F4>=$Q$1,F4<$R$1),"PM Shift","Night Shift")),"")
You could also create a small table like such:
0 6:00 14:00 22:00
Night Shift AM Shift PM Shift Night Shift
Then use a HLOOKUP to return the correct value:
=HLOOKUP(F4,O1:R2,2,TRUE)
I took a slightly different path that Scotts.
A Night Shift occurs if the time is greater or equal to 10PM, OR is less than 6AM.
=OR($F$4<$P$1,$F$4>=$R$1)
An AM Shift occurs when the time is greater or equal to 6AM, AND is less than 2PM.
=AND($F$4>=$P$1,$F$4<$Q$1)
A PM Shift occurs when the time is greater or equal to 2PM, AND is less than 10PM.
=AND($F$4>=$Q$1,$F$4<$R$1)
Stick the three conditions together and you have:
=IF(OR($F$4<$P$1,$F$4>=$R$1),"Night Shift",IF(AND($F$4>=$P$1,$F$4<$Q$1),"AM Shift",IF(AND($F$4>=$Q$1,$F$4<$R$1),"PM Shift","")))
Edit
During testing I entered 00:00:00 in A1 and =A1+TIMEVALUE("00:01:00") in A2:A1440.
At 06:00:00, 14:00:00 and 22:00:00 the changeover in shift happened a minute later.
If, however, I manually typed in 06:00:00 the changeover happened on the hour. This seems to be because TIMEVALUE is calculating 6AM as 0.2499999 rather than 0.25.
=IF(OR(HOUR(NOW())>22,HOUR(NOW())<7),"NIGHT","")&IF(AND(HOUR(NOW())>6,HOUR(NOW())<15),"MORNING","")&IF(AND(HOUR(NOW())>14,HOUR(NOW())<23),"LATE","")
I know a bit late but simplifies everything without the need of using other cells (note there are different times used).
Night - 23-07
AM - 07-15
PM - 15-23

Calculate time difference between NOW() and a calculated time

I have a cell that simply looks like 4:11 PM. Here is the formula that calculates it:
[Time In]+((TIME(8,0,0)-(K11/24))+([Lunch End]-[Lunch Start]))
I can go into that in more detail, but hopefully it's not necessary.
Now, what I want to do is display what is essentially a countdown, the difference between NOW() and 4:11 PM. Here is the closest I came:
=HOUR(NOW())-HOUR(Table1[#[Leave At]])&":"&TEXT(MINUTE(NOW())-MINUTE(Table1[#[Leave At]]),"00")
This was right until the minutes passed the comparison minutes, then it started counting back up (IE at 2:05 it said 2:06 left, but once it was 2:25 it said 2:14 left). Sorry if this is not clear.
One of the problems is, if I try TIMEVALUE(L12) (L12 being 4:11 PM) I get #VALUE!. I'm assuming this is why it's not working, and why simply doing =L12-NOW() didn't work.
How can I solve this?
The issue is NOW() is a DATE/TIME so the numeric value is >42000. Wand when subtracting it from A time which is <0 you get a negative number, so NOW() needs to be changed to just its decimal part:
=L12-TIME(HOUR(NOW()),MINUTE(NOW()),0)
Or
=L12-(NOW()-INT(NOW()))
The second will return seconds with the output.

How do i Subtract a duration from a time in Excel?

I am having an issue with Excel and it’s probably very simple but I need to get a starting time by subtracting a duration from and end time.
For example say I know that an event needs to end at 1:55:23 pm and it will take 0:22:13 what formula would I use to find out what time I should start?
I would like to be able to input the duration in the format h:mm:ss without excel trying to turn it into a time and not a duration as well.
Thank you for any suggestions
You simply subtract them.
For example...
Cell A1 has the end time: 1:55:23 PM
Cell B1 has the duration: 0:22:13 (this is the only 'strange' part because it's actually an AM time, as in minutes after midnight... but if you think about it, that's what you want).
Cell C1 has this formula: =A1-B1
That's it.
NOTE: If your duration is longer than your event start time (for example, a 4-hour event that started at 3:00 in the morning!) then the subtraction would result in a negative time.
A negative time is OK in reality, but Excel will not display it as a formatted time... instead it displays a bunch of ############. In that case, you need to display the calculation as a decimal value, which is the fraction of a day. For example. 0.25 means exactly 6 hours. If you would prefer decimal hours you simply multiply the fractional day figure by 24.

Rounding time using two cases in one formula

I want a formula for Excel work like that
08:45 turns into 8:00
and at the same time if
8:55 turns into 9:00
So I mean ignore the minutes and round it to the hour except if the minute is 55 or above round it to the next hour as shown above.
I think =TIME(IF(MINUTE(A1) >= 55; HOUR(A1)+1;HOUR(A1));0;0) is what you need.

Excel shows 1:30 passed between 12:30 and 13:00

I am trying to get a calculation of h:mm between two different times. I am using this formula
=TEXT(D21+E21, "h:mm")
When the Two cells are 12:00 and 12:30 or 12:00 and 1:00 it shows :30 and 1:00 respectively. When it is between 12:30 and 1:00, it shows 1:30. Note, all times are times of day.
Ultimately I want four cells, Time In, Time Out, Lunch In, and Lunch out, with a timespan showing time minus lunch. I am having trouble getting excel to give my anything close to accurate for nearly any input.
I recommend you don't use TEXT function. As the name implies - the result of TEXT function is a text value, which you might not be able to use in subsequent calculations. It should be sufficient to use just
=E21-D21
...then format result cell as [h]:mm
Change it to:
=TEXT(E21-D21, "h:mm")
(changed E2 to E21 to match the original question JMG)
Change it to TEXT(E21-D21, "h:mm") and also use 13:00 instead of 1:00, or add dates. It will fail if E21 is less than D21, and 1:00 is translated as 1AM. If you want to get the difference across days then add date information as well.

Resources