Formula Errors

How to Calculate Day and Night Shifts by Date and Time in Excel

Nimra MalikNimra Malik Oct 29, 2026 870 views

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.

How to Calculate Day and Night Shifts by Date and Time in Excel
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.
Before you start

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.

Solution 1Recommended

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.

1
Locate the target date and time cell

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.

2
Enter the shift calculation formula

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

3
Adjust the formula parameters

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.

4
Apply the formula to all rows

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.

Use an IF and MOD Formula to Identify Shifts
Customizing Shift Groups: If the formula returns shifts numbered 1 through 8, you can combine them into two groups (e.g., Shift 1 for values 1-4 and Shift 2 for values 5-8) by wrapping the final number calculation in an additional IF function.
Master Formulas in WPS

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. 1. Open your schedule: Launch WPS Spreadsheet and open the workbook containing your employee dates and times.
  2. 2. Select the destination cell: Click the cell where you want the calculated shift label to appear.
  3. 3. Input the formula: Paste the combined IF and MOD date formula into the formula bar and press Enter.
  4. 4. Use AutoFill: Drag the fill handle down to quickly calculate the shifts for the entire column.
100% compatibility with Microsoft Excel formulas and .xlsx file formats.Comprehensive built-in Date & Time function library for schedule management.Lightweight architecture that processes large scheduling datasets and arrays smoothly.
microsoft office alternative - wps office

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).