How to Subtract Timestamps in Excel
In this article
You subtract timestamps in Excel by taking one date-time value away from another with a plain minus formula, then formatting the result as a duration. If cell A2 holds the start time and B2 the end time, =B2-A2 gives you the difference. What goes wrong most often is not the formula but the format: Excel may show the answer as a time of day, a decimal, or a row of hashes, because it stores timestamps as numbers and formats them as dates and times. Setting the right cell format, and knowing when to multiply by 24, is the whole skill.
What You'll Need
- Excel on Windows, Mac, or the web version (the formulas and formats described here work the same across all three; only the location of the format dropdown moves slightly between desktop and web).
- Two or more cells that actually contain date-time values, not text that merely looks like one.
- An empty cell for the result, formatted as a number, time, or custom duration. Menu labels can differ slightly by version and region, so treat the exact wording as a guide.
Step-by-Step
- Confirm your timestamps are real values. Click one of the cells and look at the formula bar. A genuine timestamp such as 3/14/2026 9:15 AM appears with both a date and a time. If the formula bar shows only what the cell already displays, or if the value is left-aligned by default, it is probably text and subtraction will fail with a #VALUE! error.
- Fix text timestamps if needed. If they came from a CSV export, a chat log, or another system, the safest route is to retype one sample in Excel's own format and see whether Excel accepts it as a date. Otherwise convert them properly: select the column, use Data > Text to Columns, choose Delimited, click Next twice and set the Column data format to Date with the correct order (for example MDY), then Finish. Afterward press Ctrl+1 and apply a date-time format so Excel keeps it as a value.
- Write the subtraction formula. In an empty cell, type
=B2-A2where B2 is the later timestamp and A2 the earlier one. Excel stores every date and time as a serial number of days elapsed since 1899-12-31, so this produces a decimal representing elapsed days. Press Enter. - Format the result as a duration. Select the result cell, press Ctrl+1 (Command+1 on Mac), and choose Custom. In the Type box enter
[h]:mmfor hours and minutes that can exceed 24, or[h]:mm:ssif you want seconds too. The square brackets are essential: without them Excel rolls the display over at 24 hours and shows a small number that looks wrong. - Read the answer. A start of 3/13/2026 8:00 AM and an end of 3/14/2026 10:30 AM will now show as 26:30, meaning 26 hours and 30 minutes. That is the true elapsed time across the calendar boundary.
- Convert to decimal hours, minutes, or seconds when you need to calculate. Multiply the raw difference by 24 to get hours (
=(B2-A2)*24), by 1440 for minutes, or by 86400 for seconds. Format these results as General or Number rather than as a date or time, otherwise the decimal is hidden behind a time display. - Handle dates only when times do not matter. If both cells contain dates with no times,
=B2-A2already gives you a whole number of days. Set the format to General so it stays a plain count. - Copy the formula down the column. Drag the fill handle from the bottom-right corner of the result cell down the list. Relative references adjust automatically, so each row computes its own pair.
Common Mistakes
- Leaving the result formatted as a date. This is by far the most frequent problem. A difference of two days and change shown in date format appears as a date in 1900. Always apply a duration format or Number after subtracting.
- Forgetting the brackets in the custom format. Using
h:mminstead of[h]:mmwraps at 24 hours, so a 30-hour gap displays as 6:00. - Subtracting in the wrong order and getting a negative result. If the later timestamp is in A2 and the earlier in B2, Excel shows negative time as ######## across the whole cell.
- Mixing text and real timestamps. A column half typed and half imported will produce #VALUE! errors on some rows only, which is easy to miss.
- Assuming timestamps include a date. A cell showing only 9:15 AM has no date part, so subtracting a start time of 11:00 PM from an end time of 1:00 AM gives a negative number instead of two hours.
- Typing times with a period instead of a colon. Excel depends on your regional time separator; if your region uses a period, entering 10.30 may be read as a decimal rather than a time.
Tips
- Use
=B2-A2rather than the older DATEDIF or TIME functions for elapsed time; a direct subtraction is simpler and always exact to the second. - If you want a friendly label like "2 days 3 hours", build it with
=INT(B2-A2)&" days "&TEXT(B2-A2,"h:mm"). The INT part extracts whole days and TEXT renders the remainder. - Convert your raw timestamps to a table (Insert > Table) so the subtraction column fills itself for new rows.
- When comparing timestamps for a report, use a helper column of decimal hours and then SUM it. Totalling formatted [h]:mm cells also works, provided every cell in the sum is formatted the same way.
- To display the difference in a specific unit without helper columns, wrap the subtraction in ROUND, for example
=ROUND((B2-A2)*24,2)for hours to two decimals. - Remember that Excel's serial number system has a well-known quirk: it treats 1900 as a leap year. This only matters for dates before March 1900, which are irrelevant to normal log data.
Troubleshooting
- You see ######## filling the cell. The column is too narrow or the result is negative. Widen the column first; if the hashes remain, your start and end are reversed or your times lack dates.
- You get #VALUE!. One or both cells are text. Re-check the formula bar and use Text to Columns or a proper date-time format to convert them.
- The number looks tiny, like 0.041666. That is a fraction of a day, which equals one hour. Multiply by 24 and format as Number.
- The result changes when you reopen the file. Check whether the source data was pasted as text and converted on open. Convert it once and save the workbook in .xlsx rather than .csv so Excel keeps the values.
- You need a negative difference. Excel cannot display negative time in its default date system. Use the 1904 date system (File > Options > Advanced, scroll to the workbook calculation area) only if you understand the side effects, or calculate the absolute difference with
=ABS(B2-A2)and note that direction is lost. - Sub-second precision is required. Excel stores times to the nearest millisecond as a decimal, but display and import often round. If exact milliseconds matter, keep the source in a text-friendly format and calculate with care, or use a tool designed for log analysis.
Frequently Asked Questions
Why does my timestamp subtraction give a date like 1/2/1900?
Because the result cell is still formatted as a date. Excel interprets the small decimal as a day count since its starting date. Apply a custom [h]:mm format or switch to Number.
How do I subtract two times that cross midnight?
Include the date in both cells, then subtract normally. If the cells contain times only, use =MOD(B2-A2,1) to wrap the result into a positive elapsed time.
Can I subtract timestamps in Google Sheets the same way?
Yes. The formula =B2-A2 works identically. To show hours beyond 24, use Format > Number > Custom number format and enter [h]:mm.
How do I get total hours as a plain number?
Multiply the difference by 24 and format the cell as Number: =(B2-A2)*24. Round it if you need clean figures.
Does Excel work with time zones?
No. Excel timestamps carry no time zone information. If your data comes from different zones, convert everything to one zone before subtracting.
Why does the formula show the formula text instead of a result?
The cell is formatted as Text, or Show Formulas is switched on. Press Ctrl+1 and choose General, and check the Formulas tab for Show Formulas.