Calculation Issues

Calculate Basic and Overtime Hours Across Midnight in Excel

Ayan MasoodAyan Masood Nov 25, 2026 869 views

Question details

Calculate basic and overtime hours from employee start and finish times, including overnight shifts, with editable basic-hour limits.

Calculate Basic and Overtime Hours Across Midnight in Excel
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.
Before you start

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.

Solution 1Recommended

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.

1
Enter the basic-hours window

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.

2
Enter the shift times

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.

3
Calculate basic hours

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 overtime hours

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.

5
Format the results

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 basic and overtime hours with an editable time window
Check equal start and finish times: Time-only entries cannot distinguish a zero-hour shift from a 24-hour shift. Use actual start and finish dates and times with a different calculation if either case is possible.
Calculate shifts in WPS Spreadsheet

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. 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. 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. 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. 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.
Calculate overnight shifts using editable basic-hour limitsOpen and edit Microsoft Excel XLSX workbooksFormat results as elapsed time or decimal hoursUse a familiar spreadsheet interface for timesheets
microsoft office alternative - wps office

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.