Calculation Issues

Calculate Time Across Midnight in Excel and SharePoint

Aamir Naveed AkramAamir Naveed Akram Nov 18, 2026 869 views

Question details

Calculate a shift duration when the end time is after midnight.

Calculate Time Across Midnight in Excel and SharePoint
Product
Microsoft Excel and SharePoint
Device & OS
not provided
Scenario
A workbook stored in SharePoint records a shift starting at 16:00 and ending at 01:00.
Observed behavior
Subtracting the start time from the end time produces a negative result that may display as ######.
Before you start

Check that the start and end cells contain actual time values, not text. The MOD formula below assumes the shift is less than 24 hours and the cells contain clock times without dates.

Solution 1Recommended

Use MOD to calculate an overnight shift in Excel

Use this method for shifts under 24 hours when the start and end cells contain clock times.

A direct subtraction such as B1-A1 is negative when the end clock time is earlier than the start clock time. MOD wraps the result across midnight; the issue is with the calculation, not SharePoint.

1
Enter the shift times

In the workbook, enter 16:00 in cell A1 and 01:00 in cell B1.

2
Calculate elapsed time

In cell C1, enter =MOD(B1-A1,1).

3
Format the result

Select C1, open Format Cells, and choose Custom. Enter [h]:mm as the number format to display 9:00. If the option is unavailable in Excel for the web, open the workbook in the desktop app.

4
Use decimal hours if needed

For a decimal result, enter =MOD(B1-A1,1)*24 in C1 and apply a Number or General format. The example returns 9.

Use MOD to calculate an overnight shift in Excel
Shifts of 24 hours or longer: MOD removes whole days, so it cannot distinguish a 24-hour shift from a zero-hour shift. Record actual start and end dates as well as times, then subtract the full date-time values.
Calculate overnight shifts

Calculate Overnight Hours in WPS Spreadsheets

Use the same MOD formula in WPS Spreadsheets to calculate shifts that cross midnight, then format the result as elapsed time or decimal hours.

  1. 1. Open the workbook: Open WPS Spreadsheets and use Open to select your Excel workbook.
  2. 2. Enter the shift times: Enter the start time in A1 and the end time in B1, such as 16:00 and 01:00.
  3. 3. Enter the formula: Select C1 and enter =MOD(B1-A1,1) to calculate the elapsed time.
  4. 4. Format the result: Select C1, open Format Cells, and set the custom number format to [h]:mm. To show decimal hours instead, use =MOD(B1-A1,1)*24 and apply a Number format.
Calculate overnight shifts without negative clock-time resultsOpen and edit Microsoft Excel XLSX workbooksDisplay results as elapsed time or decimal hours
microsoft office alternative - wps office

Frequently Asked Questions

Why does Excel show ###### for an overnight shift?

Subtracting 16:00 from 01:00 gives a negative time because the formula does not account for midnight. Use =MOD(B1-A1,1) and format the result as [h]:mm. A narrow column can also display ######, so widen it if needed.

How do I show the shift duration as decimal hours?

Enter =MOD(B1-A1,1)*24 in the result cell and apply a Number or General format. A shift from 16:00 to 01:00 returns 9.

Does SharePoint cause the negative time result?

No. The result comes from subtracting a later clock time from an earlier one. Change the formula in the workbook to account for midnight.

How can I calculate a shift that lasts more than 24 hours?

Enter the actual start and end dates and times in A1 and B1, then use =B1-A1 and format the result as [h]:mm. For decimal hours, use =(B1-A1)*24 and apply a Number format.