How to Format Excel Times for Sorting and Elapsed-Time Calculations
Question details
The user needs to correctly format times in Excel to ensure accurate sorting and calculation of elapsed time intervals.

- 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.
Ensure your time data is entered in a single cell rather than split across multiple columns for hours, minutes, and AM/PM indicators.
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.
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'.
In a new column, use the formula '=EndTime-StartTime' to find the difference between the two time values.
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.
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.

Convert Text-Formatted Times Using TIMEVALUE
If your time data was imported as text and cannot be calculated, convert it into an Excel serial time value first.
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. 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. 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. 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.

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.




