Hours for a Shift That Crosses Midnight

Excel Formulas › Date & Time

All versionsMOD

A shift from 10 PM to 6 AM is 8 hours — but end − start goes negative across midnight. MOD wraps it correctly so overnight shifts total properly.


Quick formula: hours worked from start A2 to end B2 (may cross midnight):
=MOD(B2 - A2, 1) * 24
MOD(…, 1) wraps a negative day-fraction back into 0–1, so a 22:00–06:00 shift correctly reads 8 hours.

Functions used (tap for the full reference guide):

The example

10 PM to 6 AM = 8 hours.

AB
1ShiftHours
222:00 → 06:008.0
309:00 → 17:308.5

The formula

Wrap the difference with MOD:

=MOD(B2 - A2, 1) * 24 // 22:00→06:00 = 8 hours

How it works

MOD handles the midnight wrap:

  1. Times are day-fractions; end − start is negative when the end is past midnight.
  2. MOD(diff, 1) wraps any negative fraction into the 0–1 range — turning −0.667 into 0.333 (8 hours).
  3. Multiply by 24 for decimal hours, or format the result cell as [h]:mm for clock time.
  4. It works for same-day shifts too, so one formula covers both cases.

Subtract a break: =MOD(end-start, 1)*24 - breakHours. And if a shift can legitimately be 24 hours, MOD would return 0 — add a guard, since MOD treats a full day as zero.

Try it: interactive demo

Live demo

Start and end (crossing midnight is fine).

Hours:

Variations

As clock time

Format [h]:mm:

=MOD(B2-A2, 1) (format [h]:mm)

Minus a break

Subtract lunch:

=MOD(B2-A2, 1)*24 - C2

Pay for the shift

Hours times rate:

=MOD(B2-A2,1)*24 * rate

Pitfalls & errors

Don’t use plain end−start. It goes negative across midnight and shows ###### or a wrong total. MOD fixes it.

Exactly 24 hours = 0. MOD treats a full day as zero; guard if a 24-hour shift is possible.

Date+time is even cleaner. If your cells include the date, a plain subtraction works without MOD — MOD is for time-only values.

Practice workbook

📊
Download the free Hours for a Shift That Crosses Midnight practice workbook
An overnight-shift calculator with clock-time, break, and pay variants, plus 4 challenges with answers. No sign-up required.

Frequently asked questions

How do I calculate hours for an overnight shift in Excel?
Use =MOD(end - start, 1) * 24. MOD wraps the negative difference across midnight so a 22:00-06:00 shift correctly totals 8 hours.
Why does end minus start give a negative time?
When the end time is past midnight it's a smaller day-fraction than the start. MOD(diff, 1) wraps it back into a positive duration.
How do I subtract a break?
=MOD(end-start, 1)*24 - breakHours gives net worked hours.

Stop fighting formulas. Learn them in a day.

This recipe is one of hundreds of real-world formulas we teach. Our Excel Formulas & Functions class covers lookups, logic, text, and dynamic arrays hands-on — live in Dallas–Fort Worth, Houston, Austin, Oklahoma City, Denver, or online.

See the Formulas & Functions Class

Related formulas: Time difference · Timesheet overtime · Sum time past 24h

Function references: MOD