Ceiling function for rounding hours anomaly ??

August

Active Member
Joined
Jun 18, 2004
Messages
270
Hi
Cells are formatted as 00\:00 to allow me to input time without having to enter a colon.
On a time sheet an employee must have an 11 hour break between finish time and next day start time if this is broken they are compensated in 1/2 hourly payments
I'm using the Ceiling function to round to the nearest half hour, but on some occasions when there is an 11 hour break the result is still 30min penalty when it should be zero
Cell G204 is finish time on Monday (20:00), cell F205 is start time on Tuesday (07:00)
Formula is =CEILING((IF(AND($B$2-(TEXT(F204,"00\:00")-TEXT(G203,"00\:00")+(G203>F204))>0,H204>0,G203>0),$B$2-(TEXT(F204,"00\:00")-TEXT(G203,"00\:00")+(G203>F204)),0)),0.5/24)
Result is 00:30 (cell formatted hh:mm) but it should be 00:00
Also the anomaly only arises for 20:00 and 07:00, if finish time is 19:00 and start time is 06:00 the problem does not occur.

I've tried to make this as simple as possible, but I accept in advance that I may have failed here.

Thanks
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hi there. Without trying to wrap my brain around the formula itself, what is happening is due to the way excel handles numbers (all date/times are stored internally as numbers). However, times of day are repsented as fractions of a day - excel has a limit to its precision and so depending on the values being represented, very slight inaccuracies can creep in. e.g. the time 22:00 is represented as 0.916666666666667 of a day - see the below table, so your addition/subtractions may result in a tiny inaccuracy. Add or subtract a very small value (e.g. 0.000001) at the relevant point(s) and the anomaly should disappear.
Book1
JK
2036:000.25
20419:000.791666667
205
2067:000.291666667
20722:000.916666667
Sheet1

 
Upvote 0
Thank you, that makes sense
I can't have the times entered other than exact (in appearance at least), so I'll have to give it some more thought (never easy !!)

Thanks again for taking the time to reply
 
Upvote 0
Hi there. You can make the adjustment in the formula rather where the times are entered - I think this MAY do it:
Code:
=CEILING((IF(AND($B$2-(TEXT(F204,"00\:00")-TEXT(G203,"00\:00")+(G203>F204))>0,H204>0,G203>0)-0.000001,$B$2-(TEXT(F204,"00\:00")-TEXT(G203,"00\:00")+(G203>F204)),0)),0.5/24)
 
Upvote 0
I added the value in the 2nd half of the equation (after the if result) and it works

Thank you very much, I would never have thought of it
 
Upvote 0
You're welcome and thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,550
Members
449,088
Latest member
davidcom

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