Calculate Basic and Overtime Hours Across Midnight in Excel
Question details
Calculate basic and overtime hours from employee start and finish times, including overnight shifts, with editable basic-hour limits.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A timesheet uses a daily basic-hours window to separate an employee's shift into basic and overtime hours.
- Observed behavior
- The desired formulas should account for a finish time earlier than the start time and update when the basic-hours window changes.
Enter time-only values, such as 08:00, in the cells rather than text or date-and-time values. The formulas assume a basic-hours window within one day, shifts shorter than 24 hours, and different start and finish times; they do not deduct breaks.
Calculate basic and overtime hours with an editable time window
Use these formulas when basic hours fall within the same day and an employee's shift may cross midnight.
In Excel, enter the basic-hours start time in H7 and the end time in H8, such as 08:00 and 20:00. The end time must be later than the start time.
Enter the employee's start time in F11 and finish time in G11. A finish time earlier than the start time is treated as the next day.
In H11, enter =IF(G11>F11,MEDIAN(F11,G11,$H$8)-MEDIAN(F11,G11,$H$7),(G11>$H$7)*(G11-$H$7)+IF(F11>$H$8,0,$H$8-MAX(F11,$H$7))).
In I11, enter =MOD(G11-F11,1)-H11. Copy H11 and I11 down for additional shifts; the absolute references keep the basic-hours window fixed.
Select the result cells, open Format Cells, and choose Custom with the format [h]:mm. For decimal hours, multiply each result by 24 in another cell and format that cell as Number.

Calculate overnight basic and overtime hours in WPS Spreadsheet
Use the same time-window formulas in WPS Spreadsheet to separate basic hours from overtime, even when a shift ends after midnight.
- 1. Set the basic-hours window: In WPS Spreadsheet, enter the basic-hours start and end times in H7 and H8, with the end time later than the start time.
- 2. Enter the shift: Enter the employee's time-only start and finish values in F11 and G11. Use different times for a shift shorter than 24 hours.
- 3. Enter the basic-hours formula: In H11, enter =IF(G11>F11,MEDIAN(F11,G11,$H$8)-MEDIAN(F11,G11,$H$7),(G11>$H$7)*(G11-$H$7)+IF(F11>$H$8,0,$H$8-MAX(F11,$H$7))).
- 4. Calculate and format overtime: In I11, enter =MOD(G11-F11,1)-H11. Select H11 and I11, open Format Cells, and apply the custom format [h]:mm.

Frequently Asked Questions
How does the formula handle a shift that ends after midnight?
When G11 is earlier than F11, the formulas treat the finish time as occurring the next day. MOD(G11-F11,1) calculates the total shift duration, from which basic hours in H11 are subtracted.
How do I change the basic-hours window?
Update H7 and H8, for example from 08:00–20:00 to 08:00–17:00. The formulas use $H$7 and $H$8, so they continue to reference those cells when copied down.
How can I show hours as decimals instead of hours and minutes?
In another cell, multiply the time result by 24, such as =H11*24 for basic hours. Format the new cell as Number rather than a time format.
Can these formulas calculate a 24-hour shift or a shift with breaks?
No. Equal time-only start and finish values cannot distinguish zero hours from 24 hours, and the formulas do not deduct breaks. Record dates and break times and use a calculation designed for those conditions.




