Home  /  Blog  /  Date & Text
Date & Text

Time Difference in Excel — Hours Between Two Times (With Overnight Shifts)

By admin 26 November 2026 Date & Text

You have a start time and an end time, and you need the hours between them — for a timesheet, a shift, or a deadline. The rule behind every time formula is the same as the rule behind every date formula: a time is a number. One full day is 1, so 3:00 PM is 0.625 — 15 out of 24 hours — and 2:30 PM is 0.604167. That is why subtraction works: the difference between two times is a fraction of a day, and multiplying it by 24 turns it into hours. The two things that catch everyone are the format — h:mm wraps at 24 hours, so a 30-hour total shows as 6:00 — and the night shift, which goes negative unless you add a day. This guide gives you the formula first, works it through on a five-day shift table with a night shift in it, and covers overtime and adding hours.

Quick takeaway: a time is a fraction of a day — that is why subtraction works.

  • =B2 - A2 — the difference, as a fraction of a day.
  • =(B2 - A2) * 24 — the total hours, as a number you can add up.
  • =(B2 - A2) * 1440 — the total minutes.
  • =(B2 - A2) * 86400 — the total seconds.
  • [h]:mm shows a total over 24 hours. h:mm wraps at 24.
  • A night shift needs +1 or MOD, or it goes negative.
Time Difference in Excel — Hours Between Two Times (With Overnight Shifts)

The Formula — Subtract, Then Multiply

=B2 - A2
=(B2 - A2) * 24
What you wantFormulaResult for 10:35 AM → 3:30 PM
The difference as a time=B2 - A24:55
The total hours=(B2 - A2) * 244.9167
The total minutes=(B2 - A2) * 1440295
The total seconds=(B2 - A2) * 8640017,700
The hours part only=HOUR(B2 - A2)4
The minutes part only=MINUTE(B2 - A2)55

HOUR, MINUTE and SECOND extract the components, and they never exceed 24, 60 and 60 — so HOUR gives 4, not 4.9167. For a total you can add up, multiply: the difference is a fraction of a day, and 24 hours make a day.

Worked Example — A Five-Day Shift Table

DayStartEndHoursOvertime after 8h
Mon9:00 AM5:30 PM8.50.5
Tue9:00 AM5:00 PM8.00
Wed9:00 AM6:00 PM9.01.0
Thu10:00 PM6:00 AM8.00
Fri9:00 AM4:30 PM7.50
Week total41.01.5

Check the numbers: Monday is 8.5 hours, Tuesday 8, Wednesday 9, Thursday 8 (the night shift, 10 PM to 6 AM), Friday 7.5. The week total is 41 hours, and the overtime — the hours over 8 a day — is 1.5. The formula in the Hours column is =(B2 - A2) * 24, and Thursday uses the overnight version from the next section.

The Night Shift — Add a Day, or Use MOD

A shift that crosses midnight goes negative with plain subtraction: 6:00 AM minus 10:00 PM is −0.6667 of a day, which is −16 hours. There are two fixes:

=MOD(B2 - A2, 1) * 24

MOD wraps the negative difference back into the day: 6:00 AM minus 10:00 PM, wrapped, is 8 hours. The other fix is to include the date with the time — 10:00 PM on Thursday to 6:00 AM on Friday — and subtract normally. Either way, the answer is 8 hours. The full guide to the days between two dates is the months between dates guide.

Overtime After 8 Hours

=MAX(0, (B2 - A2) * 24 - 8)

MAX(0, …) keeps the answer at zero when the shift is 8 hours or less: Monday gives 0.5, Wednesday gives 1, and Tuesday, Thursday and Friday give 0. The week total is 1.5 hours of overtime. For a weekly overtime rule instead of a daily one, add the week up first and subtract the weekly limit: =MAX(0, SUM(hours) - 40) gives 1 hour on this table.

Add Hours to a Time

=A2 + 8/24

To add 8 hours to 9:00 AM, add 8/24 — 8 hours as a fraction of a day — and the answer is 5:00 PM. TIME does the same job: =A2 + TIME(8, 0, 0). The full guide to adding months to a date is the add months to date guide.

Format the Result — [h]:mm vs h:mm

FormatWhat it showsUse it for
h:mm6:00 for a 30-hour totalA time of day, or a difference under 24 hours
[h]:mm30:00 for a 30-hour totalA total over 24 hours
h:mm:ss4:55:00Hours, minutes and seconds
Number4.9167A total you will add up or multiply

The square brackets are the whole trick: [h] counts hours past 24 instead of wrapping. Without them, a 30-hour week total shows as 6:00, and the timesheet looks wrong. TEXT does the same formatting as text: =TEXT(B2 - A2, "h:mm") gives “4:55”, but the result is text, not a number — so it cannot be added up.

Common Mistakes

MistakeWhat happensFix
Your answer shows as 9:30 AM instead of 9.5The cell is formatted as a time, not a numberFormat the cell as Number, or multiply by 24
Your 30-hour total shows as 6:00h:mm wraps at 24 hoursUse [h]:mm for totals
Your night shift goes negativeThe end time is earlier in the day than the start timeUse MOD(B2 − A2, 1), or include the date
You used HOUR for the totalHOUR never exceeds 24 — it gives the hours part onlyMultiply by 24 for the total hours
You used TEXT and then tried to add the resultsTEXT returns text, not a numberUse a number format instead, or multiply by 24
Your times are text, not real times#VALUE! — subtraction cannot read themConvert them with TIMEVALUE, retype them, or rebuild them with TIME
You added 8 to add 8 hours8 is 8 days, not 8 hoursAdd 8/24, or TIME(8, 0, 0)

Frequently Asked Questions

How do I calculate the time difference in Excel? Subtract the start time from the end time: =B2 - A2. For the total hours as a number, use =(B2 - A2) * 24. For 10:35 AM to 3:30 PM, the answer is 4.9167 hours, or 4:55 as a time.

How do I calculate hours between two times in Excel? =(B2 - A2) * 24. The difference is a fraction of a day, and multiplying by 24 turns it into hours. For minutes, multiply by 1,440; for seconds, by 86,400.

How do I show a time total over 24 hours in Excel? Format the cell with [h]:mm. Without the square brackets, h:mm wraps at 24 hours, so a 30-hour total shows as 6:00.

How do I calculate a night shift that crosses midnight? Use =MOD(B2 - A2, 1) * 24, or include the date with the time. For 10:00 PM to 6:00 AM, the answer is 8 hours either way.

How do I calculate overtime after 8 hours in Excel? =MAX(0, (B2 - A2) * 24 - 8). On the shift table in this article, Monday gives 0.5 hours and Wednesday gives 1 hour.

How do I add 8 hours to a time in Excel? =A2 + 8/24, or =A2 + TIME(8, 0, 0). For 9:00 AM, the answer is 5:00 PM.

Why does my time difference show as a time instead of a number? Because the result is a fraction of a day, and the cell is formatted as a time. Format the cell as Number, or multiply by 24 to get the hours.

That is the time difference formula in Excel: subtract, then multiply by 24 for hours, 1,440 for minutes, or 86,400 for seconds — because a time is a fraction of a day. Remember the two things that matter: format a total over 24 hours with [h]:mm, or it wraps and looks wrong, and handle the night shift with MOD or a date, or it goes negative. From here, the next date and time jobs to learn are the ones this formula is built on — the months between dates guide, the add months to date guide, and the day of week formula guide — and the full learning order for the whole site is on the Excel Formulas hub.


About admin

Author of Excel formula guides on this blog.

View all guides by admin →

Keep Learning

Related guides