Dates and Times

How to Calculate Time Differences in Excel

Calculate elapsed hours, minutes or time between two times in Excel, handle shifts that cross midnight with MOD, and show totals over 24 hours.

On this page
  1. The basic difference
  2. Decimal hours and minutes
  3. Totals over 24 hours
  4. Shifts that cross midnight
  5. Times that include dates
  6. Subtract break time
  7. Round the result
  8. Make a fixed time with TIME
  9. Show the result as text
  10. Common problems
  11. Where to go next

Excel stores a time as a fraction of a day. Noon is 0.5, 6:00 AM is 0.25, and 6:00 PM is 0.75. Because of that, subtracting a start time from an end time gives the elapsed time, and multiplying the result by 24 gives decimal hours.

The basic difference

Put the start time in A2 and the end time in B2, both formatted as times. To set a time format, press Ctrl+1, choose Time, and pick a style. Then:

=B2-A2

If the start is 8:00 AM and the end is 4:30 PM, the result displays as 8:30.

Decimal hours and minutes

To show the difference as decimal hours, multiply by 24:

=(B2-A2)*24

For 8 hours and 30 minutes, the result is 8.5. For minutes, multiply by 1440, which is 24 hours times 60 minutes.

Totals over 24 hours

A time format wraps around after 24 hours, so 26 hours displays as 2:00. To show the full total, use a custom format with square brackets around the hours. Press Ctrl+1, choose Custom, and type [h]:mm. Then 26 hours shows as 26:00.

Shifts that cross midnight

Subtraction breaks when the end time is earlier than the start time. A shift from 10:00 PM to 6:00 AM gives a negative result. In Excel for Windows, a negative time shows as a row of number signs (####) instead of a value. Wrap the subtraction in MOD:

=MOD(B2-A2,1)

MOD returns the remainder after dividing by 1, which turns the negative result into the correct positive time. The same shift now displays 8:00.

Times that include dates

If each cell holds a date and a time, the subtraction is already positive. From 10:00 PM on November 24, 2026, to 6:30 AM on November 25, 2026, =(B2-A2)*24 returns 8.5. Don’t use MOD in that case, because it would drop the date and keep only the time.

Subtract break time

If a shift includes an unpaid break, subtract the break from the total. With the break start in C2 and the break end in D2, this returns the worked hours:

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

Using MOD on the break as well keeps the result right if the break crosses midnight.

Round the result

=ROUND((B2-A2)*24,2) rounds the decimal hours to two places.

Make a fixed time with TIME

TIME(hour, minute, second) creates a time value. =TIME(8,30,0) returns 8:30 AM. HOUR, MINUTE and SECOND pull parts out of a time value, in the same way YEAR, MONTH and DAY do for dates.

Show the result as text

To put the difference into a sentence as text, use TEXT with a time format. For a result under 24 hours:

=TEXT(B2-A2,“h:mm”)

For totals over 24 hours, keep the [h]:mm format on the cell instead of converting to text. The TEXT function is covered in how to use text function in excel.

Common problems

  • The cell shows ####. Either the column is too narrow or the result is negative. Widen the column, or use MOD.
  • The result shows as a decimal such as 0.354. The cell is formatted as General. Format it as a time, or use the multiply-by-24 formula.
  • The result is off by a day. If the shift crosses midnight, check that the cells hold the right dates.
  • Times stored as text. A time that Excel doesn’t recognize stays text and can return #VALUE!. The checks used for dates apply, as explained in excel not recognizing dates as dates.

Where to go next

Start with one shift and check the result by hand, then copy the formula down the column. If totals will go past 24 hours, set that column’s format to [h]:mm before you check the numbers.

The complete guide to dates and times

How to Work With Dates in Excel
Read the guide

Keep exploring

Guides from other topics

All topics →