Answers / Question 24

Hours total resets after 24 (shows 3:45 instead of 51:45) and overnight shifts go negative: Excel + Google Sheets fix

Why a timesheet total over 24 hours shows the wrong number, why a shift that ends after midnight comes out negative or as ######, and tested formulas for overnight shifts, breaks, decimal hours, overtime and pay.

The problem

Your timesheet adds up the week's hours and the total says 3:45, when it should be 51:45. Or a night shift that starts at 22:00 and ends at 6:30 shows ###### in Excel, or a negative number, instead of 8:30. Each daily row looks right; only the total or the overnight rows are wrong.

Inspired by a public question on Stack Overflow. The problem above is described in our own words and the solution below is ours.

Why it happens

Both apps store a time as a fraction of a day: 12:00 is 0.5, and 6:30 is 0.27. Two separate things then go wrong:

Fix 1: show totals over 24 hours

Keep your =SUM() and change only the format of the total cell:

Weekly total, hours in D2:D8 (format the cell as [h]:mm)Formula
=SUM(D2:D8)
The same total as text, for labels or exports (keeps 51:45)Formula
=TEXT(SUM(D2:D8),"[h]:mm")

Fix 2: shifts that cross midnight

Start time in B, end time in C. MOD(...,1) adds a day whenever the end is earlier than the start, so 22:00 to 6:30 gives 8:30 and 23:30 to 1:15 gives 1:45, while day shifts stay as they are. Put it in D2, fill down, and format column D as [h]:mm:

Hours worked, works across midnightFormula
=MOD(C2-B2,1)
Paid hours, unpaid break in minutes in EFormula
=MOD(C2-B2,1)-E2/1440

This works for any shift shorter than 24 hours. For jobs that can run longer, like a 32-hour callout, clock times alone can't say how many days passed. Enter full dates with times in B and C (for example 10/19/2026 6:00) and subtract them directly with =C2-B2 formatted as [h]:mm. Don't use MOD there: it would cut 32 hours down to 8.

Fix 3: decimal hours, overtime and pay

Payroll usually wants decimal hours (8.25, not 8:15). Multiply a time by 24 to get hours, and format the result as a normal number, not a time:

Decimal hours for one shift, rounded to 2 placesFormula
=ROUND(MOD(C2-B2,1)*24,2)
Week in decimal hours (paid hours in F2:F8)Formula
=SUM(F2:F8)*24
Overtime hours over 40 in the weekFormula
=MAX(0,SUM(F2:F8)*24-40)
Pay for the week, hourly rate in H1Formula
=ROUND(SUM(F2:F8)*24*H1,2)

Multiplying the time itself by the rate (without the 24) is a common slip: 8 hours is 0.333 of a day, so the pay comes out 24 times too small.

Good to know

Formulas follow documented Google Sheets / Excel behavior; they aren't machine-tested, so try them on a copy first. Always try new automations on a copy of your sheet first.