Yes, you can calculate duration in Excel, but it requires treating dates and times as numbers and using specific formulas to handle the midnight crossing. The core calculation relies on subtracting the start time from the end time, though you must format the result correctly to see hours, minutes, and seconds. Excel stores dates as serial numbers where 1 equals one day, and times as fractional parts of that day, allowing simple subtraction to work mathematically.

What You'll Need

  • A computer with Microsoft Excel installed (versions 2010, 2013, 2016, 2019, or Excel for Microsoft 365).
  • A dataset containing date and time values in separate columns or the same cell.
  • Basic familiarity with typing formulas into cells (starting with the equals sign).

Step-by-Step

  1. Prepare your data. Ensure your start and end values are valid date/time entries. For example, if you have a start time of 08:00 AM in cell A1 and an end time of 06:00 PM in cell B1. If these cells are formatted as "General" or text, Excel will not calculate the duration correctly; you must right-click the cell, select Format Cells, go to the Number tab, and choose Time (or Date if it includes the date component). Choose a type that shows hours, like 13:30:55 or 1:30:55 PM.
  2. Enter the basic subtraction formula. Click on an empty cell where you want the duration to appear. Type the equals sign (=), click on the cell containing your start time, type the minus sign (-), and then click on the cell containing your end time. Press Enter. For our example, the formula in cell C1 would be =A1-B1.
  3. Format the result as a duration. After pressing Enter, the result in cell C1 will likely look like a date (e.g., 1/1/1900) or a negative number (e.g., -0.6666666667). This is because Excel calculated the difference as a fraction of a day. To see this as hours, minutes, and seconds, you must change the cell format. Right-click cell C1, select Format Cells, and choose Custom. In the "Type" box, enter [h]:mm:ss. The square brackets around the h are essential; they tell Excel to show hours greater than 24, which is necessary for calculating durations that span multiple days.
  4. Handle durations crossing midnight. If your start time is later than your end time (for example, a shift that starts at 10:00 PM and ends at 6:00 AM), the simple subtraction will result in a negative number or an error. To fix this, use the MAX function. The formula =MAX(A1, B1)-MIN(A1, B1) will ensure you always subtract the earlier time from the later time. In our example, =MAX(A1, B1)-MIN(A1, B1) will calculate the correct duration of 8 hours, regardless of the order of the times.
  5. Calculate duration in decimal hours. For payroll or billing purposes, you may need the result in decimal hours (e.g., 8.5 hours instead of 8:30). To get this, use the TEXT function. The formula =TEXT(B1-A1, "h") + TEXT(B1-A1, ".mm") is a common method, but it is often simpler to use the ROUND function with a standard subtraction. First, subtract the times as in step 2 to get a decimal fraction of a day. Then, multiply the result by 24. The formula =(B1-A1)*24 will give you the hours in decimal format. You can then format the cell as Number with 2 decimal places.
  6. Calculate duration for full days and partial days. If you have a start date and an end date, and you want the total time elapsed, including whole days and leftover hours, you can simply subtract the two date cells. Excel will calculate the difference in days. To convert this to hours, multiply by 24. If you want to separate the days from the hours, you can use the INT function to get the whole days and multiply by 24, and then subtract that from the total calculated hours. For example, =(B1-A1)*24 gives total hours, and INT((B1-A1)*24) gives whole days in hours.

Common Mistakes

The most common error is forgetting to apply the custom time format [h]:mm:ss after calculating the difference. Without the brackets, Excel will only display the remainder of the 24-hour cycle, showing you 2:00 PM instead of 14:00 hours for a 14-hour shift. Another frequent mistake is not converting the end time to a 24-hour format; for instance, entering 6:00 PM as 18:00 instead of 6:00 PM can lead to incorrect calculations if the formula isn't robust enough to handle time-of-day entries mixed with duration calculations.

Tips

To quickly apply a consistent format across a column of duration results, select the column of cells, right-click, choose Format Cells, and set your preferred time or number format. This ensures your entire report looks uniform. When working with time zones, remember that Excel uses the system's local time for calculations. If you are comparing times across different regions, you must convert them to a common time zone before performing the subtraction to avoid errors.

Troubleshooting

If your calculation returns a negative number or an error when you expect a positive duration, check if your start time is chronologically later than your end time. Use the MAX and MIN functions as described in Step 4 to resolve this. If the result is a strange decimal like 0.4523 instead of 10:52, your cells are likely formatted as General or Number. Reformat them as Custom with the [h]:mm:ss format code. If you see ####### in the cell, it means the column is not wide enough to display the full time value.

Frequently Asked Questions

How do I add an hour to a time in Excel?

You can add an hour using the TIME function or simple arithmetic. To add one hour to the time in cell A1, type =A1+TIME(1,0,0). This adds 1 hour, 0 minutes, and 0 seconds. Alternatively, you can use =A1+1/24, as 1/24 represents one hour in Excel's date-time system.

Why does Excel show a date when I subtract two times?

Excel sees dates and times as serial numbers where the date is the integer part and the time is the fractional part. If you subtract two times that are very close together, the result is a small fraction that Excel may default to displaying as a date if the cell format is set to General. Changing the cell format to Custom and selecting a time format like 13:30:55 will display only the time component.

How do I calculate the difference between two dates and times?

Simply subtract the earlier date-time from the later one. For example, if cell A1 is 1/1/2023 08:00:00 and cell B1 is 1/2/2023 10:30:00, the formula =B1-A1 will return 1.10416666666667, representing 1 day and a fraction. Multiply by 24 to get the total hours, or format the cell as Custom with [h]:mm:ss to see the duration in hours, minutes, and seconds.

What does the #VALUE! error mean in duration formulas?

The #VALUE! error indicates that one or more of the cells referenced in your formula contains text or is not a valid date or time value. Ensure that the cells contain actual time entries and not text strings like "8:00 AM" unless they are properly recognized as times by Excel. You can use the ISNUMBER function to check if a cell contains a valid number before using it in a calculation.

Can I calculate duration across multiple rows at once?

Yes, you can drag the formula handle (the small square at the bottom-right corner of the cell) down to apply the calculation to all subsequent rows. This will automatically adjust the cell references for each row, allowing you to calculate the duration for every pair of start and end times in your dataset.