I would like to create a formula that can determine the number of hours worked that fall outside core hours
I am looking to create a spreadsheet to simplify some calculations, but had a hell of a time trying to suss out the logic. The main idea of the spreadsheet will be to look at shift schedules (i.e. hours worked) and compare them to the office's core hours (7am-6pm). What I envision is the following:
- User inputs the start and end times for a shift in two respective columns (B [Time In] and C [Time Out])
- Column D [Hours Worked] will have a formula to calculate the number of hours in that shift, given B & C)
- Column E [Hours Outside Core] is where I'm struggling. I would like to have it output the amount of hours in the shift that fall outside the core hours of 7am to 6pm. Shifts can go as high as 12 hours and can begin late in the afternoon or even after the core hours.
The formula I had for Column E consisted of a sum of two IF statements that looked at subtracting the difference between B (Time In) and the start time, and C (Time Out) and the end of core hours. It seems to work, but only for day shifts; if it the shift starts after core hours the formula breaks down. It is pretty messy and there are probably more elegant ways of doing it, but this is what I had:
=IF(AND(B3<TIME(7,0,0),B3>TIME(24,0,0)),(TIME(7,0,0)-B3)*24,0)+IF(C3>TIME(18,0,0),(C3-TIME(18,0,0))*24,0)
Am I sort of in the right ballpark? Any help would be greatly appreciated.
Posted Feb 25, 2016, 1:25 AM UTC · edited