Hey,
I was wondering if someone would be able to help me with this, it's a little complicated, so I do apologise for that right away.
Effectively I have two time fields for shifts, which if above 6 hours and 15 minutes will subtract a 30 minute lunch. As excel is not a big fan of calculating time, I ended up having to use an IF(TIME comparisons, which lead to me to this:
=IF(TIME(HOUR(D2),MINUTE(D2),SECOND(D2))-TIME(HOUR(C2),MINUTE(C2),SECOND(C2))>TIME(6,15,0),(TIME(HOUR(D2),MINUTE(D2),SECOND(D2))-TIME(HOUR(C2),MINUTE(C2),SECOND(C2)))-TIME(0,30,0),(TIME(HOUR(D2),MINUTE(D2),SECOND(D2))-TIME(HOUR(C2),MINUTE(C2),SECOND(C2))))
Which works just fine, until you have an occurrence where let's say the start of the shift is at 10PM and ends at 2AM, which results in a negative number and a display of #########, after a bit of google search I found out you can do a > comparison over the time calculation and effectively add a single day if the number is negative correcting the issue. Which resulted in this formula:
=IF(TIME(HOUR(D3),MINUTE(D3),SECOND(D3))-TIME(HOUR(C3),MINUTE(C3),SECOND(C3))>TIME(6,15,0),(TIME(HOUR(D3),MINUTE(D3),SECOND(D3))-TIME(HOUR(C3),MINUTE(C3),SECOND(C3)))+(TIME(HOUR(C3),MINUTE(C3),SECOND(C3))>(TIME(HOUR(D3),MINUTE(D3),SECOND(D3))))-TIME(0,30,0),(TIME(HOUR(D3),MINUTE(D3),SECOND(D3))-TIME(HOUR(C3),MINUTE(C3),SECOND(C3)))+(TIME(HOUR(C3),MINUTE(C3),SECOND(C3))>(TIME(HOUR(D3),MINUTE(D3),SECOND(D3))))
The fields being D2 or D3, does not matter in this particular case.
This formula works half way, it still subtracts the 30 minutes if the shift is lets say from 8am to 4pm as it treats it as a over the required number gap, it also calculates anything with the midnight gap by adding the one day to it resulting in accurate representation of the hours, what it does not do is deduct the 30 minutes for these crossing over shifts. Here's an example to hopefully better explain.
10:00:00 | 14:00:00 | Result 06:00:00 which is correct.
10:00:00 | 18:00:00 | Result 07:30:00 correct as 30 minutes were deducted.
22:00:00 | 06:00:00 | Result 08:00:00 Which is not correct as it should have 30 minutes subtracted, however due to the calculation being converted from a negative time it does not subtract the 30 minutes.
Is there any reasonable way to get around this?
Thank you
I was wondering if someone would be able to help me with this, it's a little complicated, so I do apologise for that right away.
Effectively I have two time fields for shifts, which if above 6 hours and 15 minutes will subtract a 30 minute lunch. As excel is not a big fan of calculating time, I ended up having to use an IF(TIME comparisons, which lead to me to this:
=IF(TIME(HOUR(D2),MINUTE(D2),SECOND(D2))-TIME(HOUR(C2),MINUTE(C2),SECOND(C2))>TIME(6,15,0),(TIME(HOUR(D2),MINUTE(D2),SECOND(D2))-TIME(HOUR(C2),MINUTE(C2),SECOND(C2)))-TIME(0,30,0),(TIME(HOUR(D2),MINUTE(D2),SECOND(D2))-TIME(HOUR(C2),MINUTE(C2),SECOND(C2))))
Which works just fine, until you have an occurrence where let's say the start of the shift is at 10PM and ends at 2AM, which results in a negative number and a display of #########, after a bit of google search I found out you can do a > comparison over the time calculation and effectively add a single day if the number is negative correcting the issue. Which resulted in this formula:
=IF(TIME(HOUR(D3),MINUTE(D3),SECOND(D3))-TIME(HOUR(C3),MINUTE(C3),SECOND(C3))>TIME(6,15,0),(TIME(HOUR(D3),MINUTE(D3),SECOND(D3))-TIME(HOUR(C3),MINUTE(C3),SECOND(C3)))+(TIME(HOUR(C3),MINUTE(C3),SECOND(C3))>(TIME(HOUR(D3),MINUTE(D3),SECOND(D3))))-TIME(0,30,0),(TIME(HOUR(D3),MINUTE(D3),SECOND(D3))-TIME(HOUR(C3),MINUTE(C3),SECOND(C3)))+(TIME(HOUR(C3),MINUTE(C3),SECOND(C3))>(TIME(HOUR(D3),MINUTE(D3),SECOND(D3))))
The fields being D2 or D3, does not matter in this particular case.
This formula works half way, it still subtracts the 30 minutes if the shift is lets say from 8am to 4pm as it treats it as a over the required number gap, it also calculates anything with the midnight gap by adding the one day to it resulting in accurate representation of the hours, what it does not do is deduct the 30 minutes for these crossing over shifts. Here's an example to hopefully better explain.
10:00:00 | 14:00:00 | Result 06:00:00 which is correct.
10:00:00 | 18:00:00 | Result 07:30:00 correct as 30 minutes were deducted.
22:00:00 | 06:00:00 | Result 08:00:00 Which is not correct as it should have 30 minutes subtracted, however due to the calculation being converted from a negative time it does not subtract the 30 minutes.
Is there any reasonable way to get around this?
Thank you