Calculation Issues

How to Format Excel Times for Sorting and Elapsed-Time Calculations

Maira MehtabMaira Mehtab Nov 4, 2026 869 views

Question details

The user needs to correctly format times in Excel to ensure accurate sorting and calculation of elapsed time intervals.

How to Format Excel Times for Sorting and Elapsed Time
Product
Excel
Device & OS
not provided
Scenario
Calculating elapsed time and sorting time data correctly when dealing with start and end times, especially when AM/PM designations are involved.
Observed behavior
Separating AM/PM into different columns or using text-formatted times leads to incorrect sorting orders and inaccurate elapsed-time calculation results.
Before you start

Ensure your time data is entered in a single cell rather than split across multiple columns for hours, minutes, and AM/PM indicators.

Solution 1Recommended

Format Cells as Time and Calculate Elapsed Time

Convert your split or text-based times into standard Excel time formats to easily sort and calculate differences.

Excel handles dates and times as serial numbers. By entering the full time (including AM/PM) into a single cell and applying the correct number format, you ensure that mathematical operations like subtraction yield accurate results.

1
Enter time properly

Enter times in one column (e.g., '1:00 PM'). Select the cells, right-click, choose 'Format Cells', go to 'Custom', and set the type as 'h:mm AM/PM'.

2
Calculate standard elapsed time

In a new column, use the formula '=EndTime-StartTime' to find the difference between the two time values.

3
Handle midnight crossovers

For time intervals that cross midnight (where the end time appears smaller than the start time), use the formula '=MOD(EndTime-StartTime, 1)' to prevent negative number errors.

4
Format total elapsed time

Select the elapsed-time result cells, open 'Format Cells', and apply the Custom format '[h]:mm'. Use the SUM function on this column to calculate total hours accurately without resetting at 24 hours.

Format Cells as Time and Calculate Elapsed Time
Formatting Trick: Using the bracketed [h]:mm format is crucial for elapsed time. It forces Excel to display cumulative hours greater than 24, rather than rolling over to zero like a standard clock.
Calculate Times Easily in WPS Spreadsheets

Easily Format Time and Calculate Durations in WPS Office

WPS Spreadsheets provides robust date and time formatting tools, seamlessly supporting the same formulas and custom formats as Microsoft Excel for quick and accurate elapsed time calculations.

  1. 1. Format Time Cells: Select your time data, press Ctrl+1 to open the Format Cells dialog, and apply the Custom format 'h:mm AM/PM'.
  2. 2. Apply Subtraction Formulas: Use standard formulas like '=B2-A2' or '=MOD(B2-A2, 1)' to instantly calculate the elapsed durations between your start and end times.
  3. 3. Sum Cumulative Hours: Use the SUM function to add up your elapsed times and apply the '[h]:mm' format to perfectly display total hours beyond a 24-hour limit.
Fully compatible with Microsoft Excel (.xlsx) files and time formatsSupports advanced date and time formatting like [h]:mm for durationsHandles complex formulas like MOD and TIMEVALUE flawlesslyLightweight, fast, and completely free to use
microsoft office alternative - wps office

Frequently Asked Questions

Why does my elapsed time show as #### in Excel?

This usually happens when the formula results in a negative time value, which often occurs when a shift crosses midnight (the end time is numerically smaller than the start time). To fix this, change your subtraction formula to =MOD(EndTime-StartTime, 1).

How do I add up total hours worked over a week?

Use the standard SUM function on your daily elapsed times, but make sure the cell containing the total is formatted as [h]:mm. The square brackets tell the software to display hours cumulatively (e.g., 42:30) rather than resetting the clock every 24 hours.

Can I use separate columns for Time and AM/PM?

While it is possible to record data this way, it is highly discouraged because spreadsheet software cannot natively sort or calculate time differences when the AM/PM indicator is separated. It is best practice to enter the complete time, like '2:30 PM', in a single cell.