How to Calculate Day and Night Shifts by Date and Time in Excel
Question details
The user wants to identify whether a specific date and time falls under a day or night shift and calculate a repeating shift number automatically using a formula.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Employee scheduling or time-tracking tasks where work hours need to be categorized into day or night shifts based on a continuous rotation schedule.
- Observed behavior
- A formula is needed to parse an existing date and time cell, determine the shift period, and assign a sequential shift number based on a specific baseline start date.
Ensure your date and time data is formatted correctly as a recognized Excel datetime value, and identify the exact date and time your first shift rotation began to set an accurate baseline.
Use an IF and MOD Formula to Identify Shifts
Combine IF, HOUR, and MOD functions to calculate the shift type and rotation number based on a 12-hour shift duration.
This formula subtracts the shift start time from the target cell, checks if the resulting hour is in the first 12 hours (Day) or the second 12 hours (Night), and calculates the day within the rotation cycle.
Click on the cell where you want to output the shift calculation. Ensure your source date and time are located in a known cell, for example, D2.
Type the following formula into the formula bar: =IF(HOUR(D2-TIME(7,0,0))<12,"Day","Night")&" Shift "&MOD(INT(D2-TIME(7,0,0))-DATE(2022,1,14),4)+1
Modify TIME(7,0,0) to match your actual shift start time (e.g., 7:00 AM). Modify DATE(2022,1,14) to the exact date your rotation started. Change the '4' in the MOD function if your rotation length differs.
Press Enter to confirm. Then, click the small square at the bottom-right corner of the cell (fill handle) and drag it down to apply the formula to the rest of your schedule.

Calculate Shifts Effortlessly with WPS Spreadsheet
WPS Spreadsheet fully supports advanced time, date, and logical functions like IF, HOUR, and MOD. You can seamlessly calculate work schedules, manage employee shifts, and handle complex data formatting with an intuitive interface.
- 1. Open your schedule: Launch WPS Spreadsheet and open the workbook containing your employee dates and times.
- 2. Select the destination cell: Click the cell where you want the calculated shift label to appear.
- 3. Input the formula: Paste the combined IF and MOD date formula into the formula bar and press Enter.
- 4. Use AutoFill: Drag the fill handle down to quickly calculate the shifts for the entire column.

Frequently Asked Questions
How do I adjust the shift start time in the formula?
In the formula, locate the TIME(7,0,0) function, which represents 7:00 AM. Change the hour, minute, and second values inside the parentheses to reflect your specific start time. For example, TIME(8,30,0) sets the start time to 8:30 AM.
Why does my shift formula return an error (#VALUE!)?
This error generally occurs if the source cell contains text rather than a valid datetime value. Select your source cell, right-click, choose 'Format Cells', and ensure it is set to a proper Date and Time format.
How can I change the length of the shift rotation cycle?
Find the divisor number in the MOD section of the formula, such as MOD(..., 4). Change the number 4 to match the total number of days in your specific shift rotation cycle (for instance, change to 7 for a weekly rotation).




