Home » excel » date – Excel Day shift and night shift schedule

# date – Excel Day shift and night shift schedule

Questions:

Lets say I have two shifts at work.

• Day shift is from 7:00 to 17:30
• Night shift is from 18:00 to 4:30

Based on this numbers I want excel to return if its “Night Shift” or “Day Shift”

This is what i have so far with the IF statement

``````=IF(Q2>=7,"DAY SHIFT",IF(Q2<=17.3,"DAY SHIFT",IF(Q2>=18,"NIGHT SHIFT",IF(Q2<4.3,"NIGHT SHIFT"))))
``````

But im not getting the results I want. Any ideas to correct the formula?

The following is what you are looking for, assuming that cell `Q2` is a Date/Time value.

``````=IF(AND(MOD(Q2,1)>=(7/24),MOD(Q2,1)<=(17.5/24)),"Day Shift",IF(OR(MOD(Q2,1)<(4.5/24),MOD(Q2,1)>=(18/24)),"Night Shift",""))
``````

The `MOD(Q2,1)` extracts the time portion of a date/time cell. These values are stored as decimal numbers, where 4:30 AM would be represented by `4.5/24 = 0.1875` (note that 30 minutes is half an hour, hence 4:30 AM is represented by 4.5/24 instead of 4.3/24, which would be 4:18 AM).

This should work:

`=IF(AND(Q2>=7,Q2<=17.5),"DAY SHIFT", "NIGHT SHIFT")`

But if you want to specify the “Night Shift”, this would be better:

``````=IF(AND(Q2>=7,Q2<=17.5),"DAY SHIFT", IF(OR(Q2>= 18, Q2<4.5), "NIGHT SHIFT",""))
``````

``````=IF(OR(Q2<4.5/24,Q2>=3/4),"Night",IF(AND(Q2>=7/24,Q2<=17.5/24),"Day","?"))&" Shift"