work

Ghana

New Member
Joined
Aug 23, 2022
Messages
4
Office Version
  1. 365
Platform
  1. Windows
I work day and night shifts and need to create a formula to take the difference between start time and finish time minus a meal break. 30 minute meal break if I work over 5 hours and 60 minute break if I work over 10 hours.
I use A2 as start time, B2 as finish time.
If anyone can please help will be appreciated
 

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.
Excel Formula:
=B2-A2-IF((B2-A2)*60*24>=(10*60),(1/24),IF((B2-A2)*60*24>=(5*60),(0.5/24),0))
 
Upvote 0
Solution
Excel Formula:
=B2-A2-IF((B2-A2)*60*24>=(10*60),(1/24),IF((B2-A2)*60*24>=(5*60),(0.5/24),0))
Hi I have used your code and it works great for day shifts. but when the shift is 23:00-07:00 it doesn't work it gives #####. Can you help please.
 
Upvote 0
Works for me, are the values in A2 (start time) and B2 (finish time) dates & times (e.g. "24/08/2022 10:00:00") or just times ("10:00:00")

If it's just times, the formula fails because it's calculating a negative time because it doesn't know that A2 and B2 actually represent times on different dates

The correct thing to do would be to make the values dates & times (so that the formula can account for that properly)

If that is not possible, then you would have to incorporate another condition along the lines of, if the time in B2 is earlier than the time in A2, then assume that B2 represents the following day to A2 (or, assume that A2 represents the preceding day to B2)

Assumptions are never a wise step to take (e.g. what exceptions are there to this? What if there were a shift that spread across three consecutive days? How would you know if there is no date element to each value?)

But, if needs must, this formula should achieve that goal :

Excel Formula:
=IF(B2>A2,B2-A2-IF((B2-A2)*60*24>=(10*60),(1/24),IF((B2-A2)*60*24>=(5*60),(0.5/24),0)),B2+1-A2-IF((B2+1-A2)*60*24>=(10*60),(1/24),IF((B2+1-A2)*60*24>=(5*60),(0.5/24),0)))

As mentioned, though, I would strongly suggest incorporating dates to remove any ambiguity
 
Upvote 0
Works for me, are the values in A2 (start time) and B2 (finish time) dates & times (e.g. "24/08/2022 10:00:00") or just times ("10:00:00")

If it's just times, the formula fails because it's calculating a negative time because it doesn't know that A2 and B2 actually represent times on different dates

The correct thing to do would be to make the values dates & times (so that the formula can account for that properly)

If that is not possible, then you would have to incorporate another condition along the lines of, if the time in B2 is earlier than the time in A2, then assume that B2 represents the following day to A2 (or, assume that A2 represents the preceding day to B2)

Assumptions are never a wise step to take (e.g. what exceptions are there to this? What if there were a shift that spread across three consecutive days? How would you know if there is no date element to each value?)

But, if needs must, this formula should achieve that goal :

Excel Formula:
=IF(B2>A2,B2-A2-IF((B2-A2)*60*24>=(10*60),(1/24),IF((B2-A2)*60*24>=(5*60),(0.5/24),0)),B2+1-A2-IF((B2+1-A2)*60*24>=(10*60),(1/24),IF((B2+1-A2)*60*24>=(5*60),(0.5/24),0)))

As mentioned, though, I would strongly suggest incorporating dates to remove any ambiguity
Thank you for your reply I have done as you said and used date & time and now works fine. Thank you again for your help
 
Upvote 0

Forum statistics

Threads
1,224,551
Messages
6,179,472
Members
452,915
Latest member
hannnahheileen

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