Excel functions to determine hours worked on day or night shift

greergyec

New Member
Joined
Jul 3, 2024
Messages
5
Office Version
  1. 2021
Platform
  1. Windows
Hi All,


Hoping someone has an easy solution to decipher if hours worked by an individual fall into the day shift (0600 - 1800) or night shift (1800 - 0600).

The issue I'm having is that if someone has worked across both shifts, I need to be able to split these according to what shift they fit into.

Last NameFirst NameDateTime Only (In)Date OutTime Only (Out)Hours
YYYYYXXXXX07/05/202416:05:0207/05/202404:30:555.22

This is the data that I'm working with, and I'm required to do it with multiple differing entries for hours all around the clock.

Any help is appreciated, I'm a novice!


Thank you!
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
First things first: How could you receive 5.22 hours from above data?
 
Upvote 0
Assuming your data (and header) is in A1:F2, then in G2 (total hours)
Excel Formula:
=(E2+F2-C2-D2)
in J2 and K2 helper values (date and time shifted 6 hours) - these columns can be hidden
Excel Formula:
=C2+D2+6/24
=E2+F2+6/24
total on night shift and on day shift in H2 and I2:
Excel Formula:
=MAX(0,MIN(K2,INT(J2)+0.5)-J2)+MAX(0,MIN(K2,INT(J2)+1.5)-(INT(J2)+1))
=MAX(0,MIN(INT(J2)+1,K2)-MAX(J2,INT(J2)+0.5))+MAX(0,MIN(INT(J2)+2,K2)-(INT(J2)+1.5))

If you had office 365 you could not use helper columns and calculate directly using LET function instead, so:
Excel Formula:
=LET(CorInT,C2+D2+6/24,CorInD,INT(CorInT),CorOutT,E2+F2+6/24,MAX(0,MIN(CorOutT,CorInD+0.5)-CorInT)+MAX(0,MIN(CorOutT,CorInD+1.5)-(CorInD+1)))
and
Excel Formula:
=LET(CorInT,C2+D2+6/24,CorInD,INT(CorInT),CorOutT,E2+F2+6/24,MAX(0,MIN(CorInD+1,CorOutT)-MAX(CorInT,CorInD+0.5))+MAX(0,MIN(CorInD+2,CorOutT)-(CorInD+1.5)))
respectively.

If your data is located in different range, move it temporarily to A1:F2, insert the formulas and then move data and formulas to their standard locations
 
Upvote 0
Solution
First things first: How could you receive 5.22 hours from above data?
Thank you so much for the response! Sorry, it is an auto calculated from the timesheet, I had changed the dates to make a more challenging example and had not changed the total hours.
 
Upvote 0
Assuming your data (and header) is in A1:F2, then in G2 (total hours)
Excel Formula:
=(E2+F2-C2-D2)
in J2 and K2 helper values (date and time shifted 6 hours) - these columns can be hidden
Excel Formula:
=C2+D2+6/24
=E2+F2+6/24
total on night shift and on day shift in H2 and I2:
Excel Formula:
=MAX(0,MIN(K2,INT(J2)+0.5)-J2)+MAX(0,MIN(K2,INT(J2)+1.5)-(INT(J2)+1))
=MAX(0,MIN(INT(J2)+1,K2)-MAX(J2,INT(J2)+0.5))+MAX(0,MIN(INT(J2)+2,K2)-(INT(J2)+1.5))

If you had office 365 you could not use helper columns and calculate directly using LET function instead, so:
Excel Formula:
=LET(CorInT,C2+D2+6/24,CorInD,INT(CorInT),CorOutT,E2+F2+6/24,MAX(0,MIN(CorOutT,CorInD+0.5)-CorInT)+MAX(0,MIN(CorOutT,CorInD+1.5)-(CorInD+1)))
and
Excel Formula:
=LET(CorInT,C2+D2+6/24,CorInD,INT(CorInT),CorOutT,E2+F2+6/24,MAX(0,MIN(CorInD+1,CorOutT)-MAX(CorInT,CorInD+0.5))+MAX(0,MIN(CorInD+2,CorOutT)-(CorInD+1.5)))
respectively.

If your data is located in different range, move it temporarily to A1:F2, insert the formulas and then move data and formulas to their standard locations
Thank you so much for this - I really appreciate the assistance! For some reason I can't get the total hours formula to calculate correctly. I am terrible with excel so I do apologise. I've attached this mini sheet, could you please enlighten me if you get the opportunity?
 
Upvote 0
Book1
ABCDEFGHIJ
1Last NameFirst NameDateTime Only (In)Date OutTime Only (Out)Total Hours
2YYYYYXXXXX01/04/20242:49:0201/04/202415:00:411.133564815
3YYYYYXXXXX01/04/20242:56:2801/04/202413:16:010.983032408
4YYYYYXXXXX01/04/20243:48:4701/04/20243:49:07
5YYYYYXXXXX01/04/20243:49:2601/04/202416:57:08
6YYYYYXXXXX01/04/20243:49:4101/04/202416:57:04
7YYYYYXXXXX01/04/20243:50:2201/04/202416:25:15
8YYYYYXXXXX01/04/20244:15:3601/04/202417:09:30
9YYYYYXXXXX01/04/20244:16:0501/04/202418:09:02
10YYYYYXXXXX01/04/20244:16:3002/04/20244:12:56
11YYYYYXXXXX01/04/20244:19:2901/04/202416:22:52
12YYYYYXXXXX01/04/20244:22:0501/04/202416:47:52
Sheet1
Cell Formulas
RangeFormula
G2:G3G2=(E2+F2-C2-D2)
 
Upvote 0
I've figured it out now! Thank you so so much!

My date column still had the time included, so I removed this and now all of the formula's are working perfectly. Thank you so much you've saved me endless amounts of work
 
Upvote 0
Glad to hear so :), I hope that after this correction of column E also other formulas (night and day shifts) work well.
 
Upvote 0

Forum statistics

Threads
1,218,213
Messages
6,141,173
Members
450,341
Latest member
switfyu2

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