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:
- The total wraps at 24. A plain time format like
h:mmshows a time of day, like a clock face. A total of 51:45 is 2 days and 3:45, so the clock shows 3:45. The sum is correct; only the display hides the full days. - Overnight shifts go negative. With clock times only, 6:30 minus 22:00 is minus 15:30, because nothing tells the sheet that 6:30 is the next morning. Excel can't display a negative time, so it fills the cell with
######. Totals that include those rows are then wrong too.
Fix 1: show totals over 24 hours
Keep your =SUM() and change only the format of the total cell:
- Excel: select the cell, press Ctrl+1, choose Custom and type
[h]:mm. The square brackets make the hours keep counting past 24. - Google Sheets: Format → Number → Duration (shows 51:45:00), or Format → Number → Custom number format and type
[h]:mm.
=SUM(D2:D8)=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:
=MOD(C2-B2,1)=MOD(C2-B2,1)-E2/1440This 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:
=ROUND(MOD(C2-B2,1)*24,2)=SUM(F2:F8)*24=MAX(0,SUM(F2:F8)*24-40)=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
- If the times were pasted from another system and SUM gives 0, they're probably text, not times. Check with
=ISNUMBER(B2).=TIMEVALUE(B2)turns a text time like10:00 PMinto a real one; the general approach is in our answer on dates stored as text. - Type times with a colon (
22:00or10:00 PM). A plain22is read as 22 days, not 22:00. - A shift of exactly 24 hours, or a start and end at the same clock time, gives 0 with MOD. Use full date-times for those.
- These formulas don't apply any overtime or break rules for you; check what your jurisdiction and contract require. This is spreadsheet help, not payroll or legal advice.
- References: Microsoft's Add or subtract time and Google's number formats help pages.
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.