Calculation Issues

Calculate Excel Shift Hours Across Midnight

Natalie TaylorNatalie Taylor Dec 2, 2026 868 views

Question details

Calculate the total duration of two shifts when either shift may end after midnight.

Calculate Excel Shift Hours Across Midnight
Product
Microsoft Excel
Device & OS
not provided
Scenario
An employee's start and end times are entered in separate cells for two shifts.
Observed behavior
Subtracting an evening start time from an after-midnight end time can produce a negative value that Excel cannot display in its standard date system.
Before you start

Check that D9 and E9 contain the first shift's start and end times, and G9 and H9 contain the second shift's times. Enter valid Excel times with AM or PM where appropriate; this method assumes each shift is shorter than 24 hours.

Solution 1Recommended

Use MOD to calculate both shift durations

Use this formula when one or both shifts may cross midnight and you need a combined duration.

1
Enter the formula

Select I9, enter =MOD(E9-D9,1)+MOD(H9-G9,1), and press Enter.

2
Format the total

Select I9 and open Format Cells with Ctrl+1 or the cell's right-click menu. Choose Custom and enter [h]:mm to show total hours, including totals over 24 hours.

3
Check the source times

If the result is incorrect, select the time cells and temporarily apply the General number format. Valid time values appear as numbers rather than time text; reenter any text values as times.

Use MOD to calculate both shift durations
Understand the time limit: MOD treats each shift as a duration under 24 hours. It cannot distinguish a zero-hour shift from a 24-hour shift or account for longer shifts using times alone.
Calculate shift hours

Calculate overnight shift totals in WPS Spreadsheets

Use the same MOD formula in WPS Spreadsheets to add two shifts that may cross midnight, then apply a duration format to show the total hours.

  1. 1. Open the spreadsheet: Open WPS Spreadsheets and use Open to select your Excel workbook.
  2. 2. Check the shift times: Enter the first shift's start and end times in D9 and E9, and the second shift's times in G9 and H9.
  3. 3. Calculate the total: Select I9, type =MOD(E9-D9,1)+MOD(H9-G9,1), and press Enter.
  4. 4. Show total hours: Select I9, open Format Cells from the right-click menu, choose Custom, and enter [h]:mm.
Calculate overnight shift durations with MODDisplay totals over 24 hours with the [h]:mm formatOpen and edit Microsoft Excel XLS and XLSX filesUse a familiar spreadsheet interface
microsoft office alternative - wps office

Frequently Asked Questions

How do I calculate just one shift that crosses midnight?

If the start time is in D9 and the end time is in E9, enter =MOD(E9-D9,1) in the result cell. Format the result as [h]:mm.

Why does my total reset after 24 hours?

A standard time format can display the time of day rather than the full duration. Open Format Cells, choose Custom, and use [h]:mm to display accumulated hours.

How can I tell if a clock-in value is stored as text?

Select the source cell and temporarily apply the General number format. A valid Excel time appears as a numeric value, while a text entry remains text.

Can this formula calculate a shift longer than 24 hours?

No. MOD with a divisor of 1 discards whole days. For longer shifts, enter complete start and end dates and times, subtract the start from the end, and format the result as [h]:mm.