Spreadsheet Practice

How to calculate time worked across midnight in Excel

Formula (Excel and Google Sheets)

=MOD(C2-B2,1)*24

Wrap the difference in MOD: =MOD(C2-B2,1)*24. A negative overnight difference becomes the right number of hours.

Result on the example
one result per row in D2, filled down to D7
Works in
Every current version
Google Sheets
Same formula

See it work

The formula is already in D2, filled down to D7. Change any input and the result updates, or edit the formula to experiment.

How it works

A shift from 10:00 PM to 6:30 AM gives a negative difference, -0.65 of a day. MOD(…,1) wraps negative values into the next day, so it becomes 0.35, which is 8.5 hours. Day shifts are unchanged, because MOD leaves values between 0 and 1 alone.

=MOD(C2-B2,1)*24

Result8.5

  1. C26:30 AM

    The value in C2.

  2. B210:00 PM

    The value in B2.

  3. C2-B2-0.6458333333

    The - operator subtracts.

  4. MOD(C2-B2,1)0.3541666667

    MOD: Remainder after division.

    • numberC2-B2-0.6458333333
    • divisor1
  5. MOD(C2-B2,1)*248.5

    The * operator multiplies.

In Google Sheets

The same formula works in Google Sheets: =MOD(C2-B2,1)*24. We ran it in Google Sheets mode on the same data and it returns the same results.

Other ways to do it

Each one was run on the same example sheet.

FormulaResultWhen to use it
=(C2-B2+(C2<B2))*248.50, 12.00, 7.75…Adds one day when the end time is earlier than the start; the same result.
=MOD(C2-B2,1)0.35, 0.50, 0.32…Different resultThe duration as a time. Format the cell as h:mm to show 8:30. A fraction of a day.

Common mistakes

  • Plain C2-B2 on a night shift is negative, and Excel shows #### for a negative time.
  • MOD assumes the shift is shorter than 24 hours. For longer spans, record the dates too and subtract the full date-times.

Try it yourself

Same data, empty answer cell. Your formula is graded instantly, then re-checked on changed data, so a typed-in number won't pass.

Calculate time worked across midnight

In D2, calculate the hours worked for each shift, including shifts that end after midnight, and fill down to D7.

Questions

How do I total a week of night shifts?

Sum the hours column, or =SUMPRODUCT(MOD(C2:C7-B2:B7,1))*24.

How do I show 8:30 instead of 8.5?

Leave out *24 and format the cell as h:mm.

Checked by running on 2026-10-30: every formula and result on this page was calculated by the Spreadsheet Practice formula engine, in both Excel and Google Sheets modes.