Calculate Time Differences in Excel and Google Sheets

Spreadsheet date and time values can be subtracted to calculate a duration, but formatting, midnight and date context affect the result.

Calculate Time Differences in Excel and Google Sheets: Start, Enter date and time; End, Enter date and time; Difference, Format as duration.

Dates and times as spreadsheet values

Excel and Google Sheets represent dates and times using serial values. A whole-day change changes the serial value by one, and a time of day is represented as a fraction of a day. That makes subtraction convenient when the cells contain actual date or time values rather than text that only looks like a date.

For a start in cell A2 and an end in B2, =B2-A2 calculates a difference in days. Format the result as a duration when you want to display hours and minutes. To express the result as a decimal number of hours, multiply by 24 and use an ordinary number format.

Calculating an overnight shift

The clearest approach is to enter both the date and time for each endpoint. A shift starting on Monday at 22:00 and ending on Tuesday at 06:00 then has a positive eight-hour difference. The dates make the intended midnight crossing explicit and also support intervals longer than one day.

If the cells contain only times and an end earlier than the start always means the next day, a formula such as =MOD(B2-A2,1) can represent an overnight interval shorter than one day. It cannot infer whether an equal time means zero hours or a full day, and it loses information about intervals of 24 hours or more. Record dates when those cases are possible.

Formatting durations over 24 hours

A clock-time format can wrap around at 24 hours. For a duration that may exceed a day, use the spreadsheet's elapsed-hour format, commonly [h]:mm, rather than an ordinary time-of-day format. Confirm the format in the specific application and locale.

Formatting does not change the stored value. If a result appears as a date or an unexpected clock time, inspect the cell format before changing the formula. When the result is negative, display support and behavior can vary between applications and settings; verify how your workbook handles negative durations.

Time zones and daylight saving

A local clock reading alone does not always determine elapsed time. On a day when clocks change, the wall-clock difference across a shift can differ from the actual elapsed duration. Spreadsheet cells do not automatically supply a named time zone or resolve a repeated local time merely because they contain a date and time.

For an exact cross-zone or transition-sensitive calculation, record the zone and resolve both endpoints to instants using a suitable time-zone-aware tool. For a human schedule, also retain the original local readings. Read daylight saving time and calendar versus elapsed time.

Days, weekdays and holidays

A date difference can mean all calendar days or only working days. Weekday or business-day functions can help, but the result depends on the weekend pattern, the holiday list and whether each endpoint counts. A list of holidays is only as complete as the data entered into the workbook.

Before using a result for payroll or a deadline, check the relevant policy and document the assumptions. Our date difference calculator counts calendar days and offers an inclusive-end option. For the meaning of working days, see What Is a Business Day?

Worked examples

Suppose A2 holds a shift start of 22:00 and B2 an end of 06:30 the next morning, with times only and no dates.

  • =MOD(B2-A2,1) gives 0.354166…, which displays as 8:30 with the h:mm format.
  • =MOD(B2-A2,1)*24 gives 8.5 hours, which is useful for pay calculations.
  • =MOD(B2-A2,1)*1440 gives 510 minutes.

If the cells hold full date-times, such as 2026-12-04 22:00 and 2026-12-06 06:30, a plain =B2-A2 gives 1.354…, and the [h]:mm format shows 32:30. Without the square brackets Excel shows 8:30, because the ordinary h format wraps at 24 hours.

Why spreadsheets behave this way

Excel stores a date as a whole number of days and a time as a fraction of a day. In the default 1900 date system, day 1 is 1 January 1900. For compatibility with Lotus 1-2-3, Excel also treats 1900 as a leap year, so serial 60 is a 29 February 1900 that never happened. The 1904 date system, still used by some older Mac workbooks, is 1,462 days off. Copying dates between the two systems moves them by about four years. A negative time result shows as ##### in the 1900 system, which is one more reason to use MOD for overnight shifts.

For whole years, months or days between two dates there is DATEDIF(start, end, "y") with the units "m" and "d". Microsoft warns that the "md" unit can give wrong results, so avoid it for anything important. Google Sheets uses the same serial-number idea, counting from 30 December 1899.

Common questions

Why does my result show a date such as 0/1/1900?

The cell has a date format. The value is a duration, so change the format to [h]:mm or multiply by 24 to get decimal hours.

Do these formulas handle daylight saving?

No. Spreadsheet times have no time zone, so an overnight shift that crosses a clock change will be off by an hour. Record UTC times, or adjust those shifts by hand.

Sources and further reading