How to Get Duration in Excel: Calculate Time Differences
In this article
To get the duration between two times in Excel, subtract the start time from the end time using a simple formula (=End_Time - Start_Time) and then apply a custom number format to ensure the result displays as hours and minutes rather than a decimal or a time of day. This process allows you to track project timelines, employee shifts, or event lengths by leveraging Excel's internal system where one whole day equals the number 1.
What You'll Need
- Microsoft Excel (any modern version for Desktop, Web, or Mobile).
- A dataset containing at least two columns: one for the start time/date and one for the end time/date.
- Consistent time formatting (e.g., all entries should be in the same time zone and format).
Step-by-Step
- Enter Your Data: Create two columns. In Column A, enter your start times (e.g., 8:00 AM). In Column B, enter your end times (e.g., 5:00 PM). Ensure you include the AM/PM designator or use 24-hour military time so Excel recognizes the entry as a time value rather than plain text.
- Insert the Subtraction Formula: Click on the cell where you want the duration to appear (e.g., Cell C2). Type
=B2-A2and press Enter. This tells Excel to find the difference between the two points in time. - Address the Default Formatting: By default, Excel may display the result as a time of day (e.g., 9:00 AM) or a decimal number. This is because Excel treats time as a fraction of a 24-hour day. To see the actual duration, you must change the cell format.
- Open the Format Cells Menu: Right-click the result cell (C2) and select Format Cells... from the context menu. Alternatively, you can use the keyboard shortcut
Ctrl + 1on Windows orCmd + 1on Mac. - Apply Custom Duration Formatting: In the Format Cells dialog box, go to the Number tab. In the Category list on the left, select Custom. In the Type input box, delete whatever is there and type
[h]:mm. The square brackets around the 'h' are critical; they tell Excel to accumulate hours beyond 24 rather than resetting to zero every time a full day passes. - Apply to Remaining Rows: Hover your mouse over the bottom-right corner of cell C2 until the cursor turns into a small black cross (the fill handle). Click and drag the handle down to apply the formula and the formatting to all other rows in your dataset.
- Summing Total Duration: If you need the total duration of multiple tasks, use the
=SUM()function at the bottom of your duration column. Ensure this total cell is also formatted as[h]:mm, otherwise, a total of 30 hours will appear as 6 hours (30 minus one full 24-hour cycle).
Common Mistakes
One of the most frequent errors is forgetting the square brackets in the custom format. If you use h:mm, Excel treats the result as a clock time. For example, if a project took 25 hours, h:mm will display as 1:00 because it ignores the 24-hour cycle. Using [h]:mm ensures that 25 hours is displayed as 25:00.
Another common mistake is entering times as text. If you type "8am" instead of "8:00 AM", Excel may treat the entry as a string of text rather than a numeric value. When you try to subtract text, Excel will return a #VALUE! error because you cannot perform mathematical operations on text strings.
Users also often forget to include dates when durations span across midnight. If a shift starts at 10:00 PM on Monday and ends at 6:00 AM on Tuesday, the formula =End-Start will result in a negative number. Excel cannot display negative times by default and will show a series of hash symbols (#######) in the cell.
Tips
To handle durations that cross midnight without entering full dates, you can use a logical IF statement or the MOD function. The formula =MOD(B2-A2, 1) is a clever trick that forces the result to remain positive by wrapping the calculation within a 24-hour cycle. This is perfect for overnight shifts where the end time is numerically smaller than the start time.
If you need the duration as a decimal number (e.g., 8.5 hours instead of 8:30), you must multiply the result by 24. Because Excel stores time as a fraction of a day, 8 hours and 30 minutes is stored as 0.35416. Multiplying (B2-A2)*24 converts this into a standard decimal. After doing this, change the cell format to Number or General, as the [h]:mm format will no longer work for decimal values.
For highly precise tracking, you can include seconds in your custom format. Use [h]:mm:ss to see exactly how many seconds elapsed between two timestamps. This is particularly useful for logs, race times, or technical system uptimes.
Troubleshooting
If your result shows a series of hash symbols (#######), the most likely cause is a negative time result. This happens when the start time is later than the end time (common in overnight shifts). To fix this, either add the date to your time entries (e.g., 1/1/2023 22:00) or use the =MOD(B2-A2, 1) formula mentioned in the Tips section.
If the formula returns a #VALUE! error, check your data entry. Ensure there are no leading or trailing spaces in your time cells. You can use the =TRIM() function to clean your data if it was imported from another software. Also, verify that your regional settings match the time format you are using; for example, some regions use a period instead of a colon to separate hours and minutes.
If the duration looks correct but the SUM total is wrong, check the formatting of the total cell. If your total is 48 hours but the cell says 0:00, it is because the cell is formatted as h:mm. Change it to [h]:mm to show the cumulative total.
Frequently Asked Questions
How do I calculate duration if the times are in different days?
The best way is to enter both the date and the time in the same cell (e.g., 2023-10-01 08:00). When you subtract the start cell from the end cell, Excel automatically calculates the total number of days and hours between them. You can then format the result as [h]:mm to see the total hours.
Can I calculate duration using a formula instead of custom formatting?
Yes, you can use the TEXT function to convert the duration into a readable string. For example, =TEXT(B2-A2, "[h]:mm") will return the duration as text. Note that you cannot easily sum these results because they are no longer numeric values.
Why does Excel show a decimal like 0.375 when I subtract times?
Excel stores time as a fraction of a 24-hour day. 0.5 equals 12 hours, and 0.25 equals 6 hours. To fix this, change the cell format to Time or use the Custom format [h]:mm.
How do I subtract a break time from the total duration?
Simply subtract the break duration from your initial result. If your duration is in C2 and your break (e.g., 0:30 for 30 minutes) is in D2, use the formula =C2-D2. Ensure the break cell is also formatted as a time value.
What is the difference between h:mm and [h]:mm?
The h:mm format is for time-of-day and resets every 24 hours. The [h]:mm format is for elapsed duration and continues to count hours indefinitely, which is necessary for totaling time across multiple days.