Calculation Issues

Calculate Excel Shift Hours Across Midnight and Subtract Breaks

Chanuka GeekiyanageChanuka Geekiyanage Nov 18, 2026 869 views

Question details

Calculate paid shift hours when a shift crosses midnight and subtract an unpaid break.

Calculate Shift Hours Across Midnight in Excel
Product
Microsoft Excel
Device & OS
not provided
Scenario
A worksheet records a shift start time, end time, and unpaid break entered in decimal hours.
Observed behavior
Simple time subtraction gives an incorrect result for a shift that ends after midnight, and the break must be converted from hours to an Excel time value.
Before you start

Enter the start and end as recognized Excel times, such as 7:00 PM and 3:00 AM. Enter the unpaid break as decimal hours, such as 0.5 for 30 minutes.

Solution 1Recommended

Use a Formula to Calculate Overnight Shift Time

Use this formula when start and end times are in C5 and D5, and the unpaid break in E5 is entered in decimal hours.

Excel stores times as fractions of a day, so dividing the break by 24 converts decimal hours to a time value. The comparison adds one day when the end time is earlier than or equal to the start time.

1
Enter the shift details

Enter the start time in C5, the end time in D5, and the unpaid break in decimal hours in E5. For example, enter 7:00 PM, 3:00 AM, and 0.5.

2
Calculate paid time

Select an empty result cell and enter =D5-C5-E5/24+(D5<=C5). Press Enter.

3
Format the result

Select the result cell, press Ctrl+1, and choose Custom under Number. Enter [h]:mm to display the example result as 7:30.

4
Display decimal hours if needed

For a numeric result instead, enter =(D5-C5-E5/24+(D5<=C5))*24 and format the result cell as Number. The example returns 7.5.

Use a Formula to Calculate Overnight Shift Time
Equal start and end times: The formula treats equal start and end times as a 24-hour shift before deducting the break. It assumes the shift is no longer than 24 hours; use actual dates and times for longer shifts.
Calculate shift hours in WPS

Calculate Overnight Shifts in WPS Spreadsheets

Use the same overnight shift formula in WPS Spreadsheets, then format the result as elapsed time or decimal hours.

  1. 1. Open the worksheet: Open WPS Office, select Spreadsheets, and open your workbook.
  2. 2. Enter shift and break values: Enter the start time in C5, the end time in D5, and the break in decimal hours in E5.
  3. 3. Enter the formula: Select an empty cell, enter =D5-C5-E5/24+(D5<=C5), and press Enter.
  4. 4. Format the result: Open Format Cells for the result cell and choose the custom format [h]:mm. To show decimal hours instead, multiply the entire formula by 24 and use a number format.
Calculates paid time for shifts that cross midnightSubtracts unpaid breaks entered in decimal hoursOpens and saves Microsoft Excel XLSX filesProvides familiar spreadsheet formulas and number formats
microsoft office alternative - wps office

Frequently Asked Questions

Why does subtracting the start time from the end time fail after midnight?

When cells contain times without dates, 3:00 AM is numerically earlier than 7:00 PM. Adding (D5<=C5) to the formula adds one day for an overnight shift.

Why do I divide the break by 24?

Excel stores one hour as 1/24 of a day. If E5 contains 0.5 to mean half an hour, E5/24 converts it to an Excel time value before subtraction.

What if the break is entered as a time such as 0:30?

If E5 contains a recognized Excel time value, subtract E5 directly: =D5-C5-E5+(D5<=C5). Do not divide it by 24 again.

How do I show the result as 7.5 hours instead of 7:30?

Enter =(D5-C5-E5/24+(D5<=C5))*24 in the result cell, then use Format Cells to select a Number format.

What happens if the start and end times are the same?

The formula treats equal times as a 24-hour shift before subtracting the break. If equal times should mean no shift in your worksheet, use a different rule for those rows.