Excel Datetime Difference: How to Calculate Time Gaps
In this article
To find the difference between two datetimes in Excel, subtract the start date/time cell from the end date/time cell (e.g., =B2-A2) and then apply a custom number format to display the result as hours, minutes, or days. Because Excel stores dates as whole numbers and times as decimals, a simple subtraction provides the raw difference in days, which can then be converted into any time unit using formatting or multiplication.
What You'll Need
- Microsoft Excel (any modern version including Office 365, 2021, 2019, or Excel for the Web).
- A dataset containing at least two columns: one for the start datetime and one for the end datetime.
- Data entered in a format Excel recognizes as a date and time (e.g.,
YYYY-MM-DD HH:MM).
Step-by-Step
- Prepare Your Data: Ensure your datetimes are in separate cells. For example, place your start date and time in cell A2 (e.g.,
2023-10-01 08:00) and your end date and time in cell B2 (e.g.,2023-10-03 14:30). If the data is aligned to the right of the cell, Excel recognizes it as a number/date; if it is aligned to the left, it is likely text and must be converted first. - Enter the Subtraction Formula: Click on the cell where you want the result to appear (C2). Type the equals sign
=, click the end datetime cell (B2), type the minus sign-, and then click the start datetime cell (A2). Your formula should look like=B2-A2. Press Enter. - Analyze the Initial Result: By default, Excel may display the result as a date or a decimal. For example, if the difference is 2 days and 6.5 hours, Excel might show a date like
1900-01-02or a number like2.27. This is because the integer represents days and the decimal represents the fraction of a 24-hour day. - Apply Custom Formatting for Hours/Minutes: To see the total elapsed time rather than a date, right-click the result cell (C2) and select Format Cells. In the Category list, select Custom. In the Type box, enter
[h]:mm:ss. The square brackets around thehare critical; they tell Excel to calculate total elapsed hours beyond 24, rather than resetting the clock to zero every time a full day passes. - Convert Difference to Specific Units (Optional): If you need the result as a plain number (e.g., total hours as a decimal) rather than a time format, use multiplication:
- For Total Hours: Use
=(B2-A2)*24. Format the cell as Number. - For Total Minutes: Use
=(B2-A2)*1440(since 24 * 60 = 1440). Format the cell as Number. - For Total Seconds: Use
=(B2-A2)*86400(since 24 * 60 * 60 = 86400). Format the cell as Number.
- For Total Hours: Use
- Using the TEXT Function for Labels: If you want the result to be a text string like "2 Days, 6 Hours", use a combination of functions:
=INT(B2-A2) & " Days, " & TEXT(B2-A2, "h \"Hours\""). This converts the integer part of the subtraction to days and the remainder to hours.
Common Mistakes
The most frequent error is forgetting the square brackets in the custom format. If you use h:mm instead of [h]:mm, Excel will only show the remainder of the day. For instance, if the difference is 26 hours, h:mm will display 2:00 because it subtracts the full 24-hour day. Always use [h] for cumulative durations.
Another common mistake is subtracting the end date from the start date (=A2-B2), which results in a negative number. Excel cannot display negative time values by default and will instead show a series of hash symbols (#######) filling the cell. Always subtract the earlier date from the later date.
Users also often confuse Date cells with Text cells. If you imported data from a CSV or a website, the datetimes might look correct but be stored as text strings. Subtraction formulas will return a #VALUE! error if one or both cells are not recognized as numeric date values.
Tips
To handle calculations that should exclude weekends and holidays, avoid simple subtraction and use the NETWORKDAYS function. While NETWORKDAYS only calculates full days, you can combine it with time subtraction by calculating the time difference for the first and last day separately and adding the network days in between.
If you are working with very large datasets, use the DATEDIF function for specific intervals. For example, =DATEDIF(A2, B2, "d") returns the total number of complete days, while "m" returns complete months and "y" returns complete years. Note that DATEDIF is a "hidden" function in Excel—it will not appear in the autocomplete list when you start typing, but it works perfectly when entered fully.
For real-time tracking, use the NOW() function as your end date. For example, =NOW()-A2 will give you the elapsed time from a fixed start date to the current moment. Every time the sheet recalculates, this value will update.
Troubleshooting
If you see #VALUE!: This almost always means your datetimes are stored as text. To fix this, select the column of dates, go to the Data tab, select Text to Columns, click Next twice to reach Step 3, select Date (choose the format that matches your data, e.g., MDY), and click Finish. This forces Excel to re-evaluate the text as actual dates.
If you see #######: Check if your result is negative. If the start date is after the end date, the result is negative, and Excel's standard time format cannot render it. Ensure the formula is =End-Start. If you absolutely need to show negative time, you must change your workbook settings: go to File > Options > Advanced, scroll down to the When calculating this workbook section, and check Use 1904 date system. Be careful, as this can shift existing dates in your sheet by four years.
If the result is a weird date (e.g., January 1900): This is not an error; it is a formatting issue. Excel is treating the result (e.g., 2.5 days) as a date starting from its epoch (January 0, 1900). Change the cell format to Number or Custom [h]:mm to see the duration instead of the calendar date.
Frequently Asked Questions
How do I calculate the difference between two times on the same day?
The process is identical to datetime subtraction: =End_Time - Start_Time. Ensure both cells are formatted as Time and the result cell is formatted as h:mm or [h]:mm.
Can I calculate the difference in minutes only?
Yes. Subtract the cells and multiply by 1440 (the number of minutes in a day). Formula: =(B2-A2)*1440. Make sure to format the result cell as Number or General, not as Time.
What is the difference between NOW() and TODAY()?
TODAY() returns only the current date (midnight), while NOW() returns the current date and the current time. For precise datetime differences, always use NOW().
Why does my time difference reset after 24 hours?
This happens because you are using the h:mm format, which acts like a clock. To show cumulative hours (e.g., 30 hours instead of 6 hours), use the custom format [h]:mm.
How do I exclude non-working hours from the difference?
This requires a complex formula involving NETWORKDAYS and the subtraction of start/end times from the workday boundaries. Simple subtraction cannot filter for specific hours of the day.