Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Duration in Excel: How to Calculate Time Differences

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

To calculate duration 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, minutes, and seconds rather than a decimal or a time of day. This process allows you to track work hours, project timelines, or event lengths accurately by leveraging Excel's internal system of treating one full day as the integer value 1.

What You'll Need

  • Microsoft Excel (any modern version).
  • A dataset containing at least two columns: a start time/date and an end time/date.
  • Consistent data entry (ensure times are entered in a format Excel recognizes, such as HH:MM or HH:MM AM/PM).

Step-by-Step

  1. 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). If your duration spans multiple days, you must enter both the date and the time in the cell (e.g., 2026-12-01 08:00).
  2. Insert the Subtraction Formula: Click on the cell where you want the duration to appear (e.g., cell C2). Type =B2-A2 and press Enter. Excel will subtract the start time from the end time.
  3. Apply the Basic Time Format: If the result looks like a decimal or a strange time of day, you need to change the cell format. Right-click the result cell and select Format Cells.... In the Category list on the left, select Time and choose a format like 13:30.
  4. Handle Durations Over 24 Hours: If your calculated duration exceeds 24 hours, Excel's default time formats will "reset" to zero (for example, 25 hours will show as 1 hour). To fix this, go back to Format Cells..., select Custom from the category list, and in the Type box, manually type [h]:mm:ss. The square brackets tell Excel to accumulate hours rather than rolling them over into a new day.
  5. Convert Duration to Decimals (Optional): If you need to multiply the duration by an hourly rate (e.g., for payroll), you cannot use the time format because Excel treats time as a fraction of a day. To convert the duration to a decimal number of hours, use the formula =(B2-A2)*24. Then, change the cell format to Number or General.
  6. Summing Multiple Durations: To find the total duration of several tasks, use the =SUM(C2:C10) function. Crucially, you must apply the [h]:mm:ss custom format to the total cell, otherwise, the sum will appear incorrect once it passes 24 hours.

Common Mistakes

One of the most frequent errors is entering times as text. If you type "8 hours" into a cell, Excel treats it as a string of letters, not a numerical value, and any formula attempting to subtract it will return a #VALUE! error. Always enter times using colons (e.g., 8:00) and let the formatting handle the labels.

Another common pitfall is ignoring the date. If a shift starts at 10:00 PM on Monday and ends at 6:00 AM on Tuesday, a simple End - Start formula will result in a negative number or a series of hash marks (#######) because Excel cannot display negative time by default. To solve this, you must either include the full date in the cell or use a formula that accounts for the midnight crossover, such as =IF(B2<A2, B2+1-A2, B2-A2).

Users also often confuse the h:mm format with the [h]:mm format. The former is for a "time of day" (clock time), while the latter is for "elapsed time" (duration). Using the clock format for a total of 40 work hours will result in the cell displaying 16:00 (because 40 hours is one day and 16 hours), which is misleading and incorrect for reporting.

Tips

To speed up data entry, use the keyboard shortcut Ctrl + Shift + : (colon) to insert the current system time into a cell instantly. This is highly useful for time-tracking logs where you mark the exact moment a task begins and ends.

For more complex duration needs, consider using the TEXT function to create a readable summary. For example, =TEXT(B2-A2, "h" & " hours, " & "m" & " minutes") will convert the numerical duration into a sentence like "8 hours, 30 minutes," which is better for presentations or client-facing reports.

If you are working with very precise durations, such as in scientific data or athletic timing, remember that Excel can track milliseconds. Use the custom format [h]:mm:ss.000 to see the fractional seconds. This ensures that rounding errors do not accumulate when summing thousands of small time increments.

Troubleshooting

If you see a cell filled with hash marks (#######), it usually means one of two things: the column is too narrow to display the result, or the formula has resulted in a negative time value. First, try widening the column. If that doesn't work, check your start and end times. If the end time is numerically smaller than the start time (e.g., ending at 2:00 AM after starting at 11:00 PM), Excel produces a negative result. Use the MOD function to fix this: =MOD(B2-A2, 1). This formula automatically handles midnight crossovers by wrapping the result back into a positive 24-hour cycle.

If your formula returns a #VALUE! error, check for hidden spaces in your cells. Sometimes data imported from other software includes a leading or trailing space that makes Excel think the time is text. You can use the =TRIM() function to clean the data or use the Find and Replace tool (Ctrl + H) to remove unnecessary spaces.

If the sum of your durations seems far too low, check the formatting of the total cell. If you see 4 hours instead of 28 hours, you have used the standard h:mm format. Change it to [h]:mm via the Format Cells menu to reveal the true accumulated total.

Frequently Asked Questions

How do I calculate duration between two dates and times?

Simply subtract the start cell from the end cell (=End_DateTime - Start_DateTime). Ensure both cells contain both the date and the time. Format the result cell as [h]:mm to see the total hours elapsed across multiple days.

Can I calculate duration in minutes only?

Yes. Subtract the times and multiply the result by 1440 (the number of minutes in a day: 24 * 60). The formula is =(B2-A2)*1440. Ensure the cell format is set to Number or General.

How do I exclude weekends from a duration calculation?

Use the NETWORKDAYS function. For example, =NETWORKDAYS(A2, B2) - 1 will give you the number of full working days between two dates. To include specific hours, you will need a more complex formula that subtracts non-working hours from the total.

Why does my duration show as a decimal like 0.35?

Excel stores time as a fraction of a 24-hour day. 0.5 equals 12 hours. To fix this, change the cell format from General to Time or use a Custom format like [h]:mm.

How do I subtract a break time from a total duration?

If your duration is in cell C2 and your break duration (e.g., 0:30 for 30 minutes) is in cell D2, use the formula =C2-D2. Ensure all cells are formatted as Time or Custom [h]:mm.