Sub topic 12
Time and Elapsed-Time Formats
This chapter assumes you know that Excel stores dates as serial numbers (the previous chapters covered this). It also assumes you can apply a custom format through Format Cells. Here you will learn how Excel stores a time of day, how to display clock times and durations, and why the same format code can behave differently depending on its position.
Time is a fraction of a day
Excel stores a date as a whole number and a time as the fraction after the decimal point. One full day is 1, so every hour is 1/24 of a day.
| Time of day | Stored value |
|---|---|
| 00:00 (midnight) | 0 |
| 06:00 | 0.25 |
| 12:00 (noon) | 0.5 |
| 18:00 | 0.75 |
| 23:59:59 | 0.99998843 |
A cell holding 45292.75 is 1 January 2024 at 18:00. Apply a date format and you see the date. Apply a time format and you see 18:00. The stored value does not change.
=TIME(14,30,0)This returns 0.604166667, which displays as 2:30 PM once a time format is applied. If the cell still shows a decimal, the format is General and you need to apply a time format.
Clock-time format codes
Time codes are letters you combine in a custom format.
| Code | Meaning | Example (0.604166667) |
|---|---|---|
| h | Hour, no leading zero | 14 |
| hh | Hour, two digits | 14 |
| m | Minute, no leading zero | 30 |
| mm | Minute, two digits | 30 |
| s, ss | Seconds | 0, 00 |
| AM/PM | Switches to a 12-hour clock | 2:30 PM |
Without AM/PM, Excel uses a 24-hour clock.
h:mm AM/PMThis displays 2:30 PM. The built-in Time category in Format Cells offers similar choices. Use a custom code when you need something specific, such as hh:mm:ss.
The m ambiguity
The letter m means both month and minute. Excel decides by position. It treats m or mm as minutes only when it follows an h code or comes before an s code. Otherwise it treats it as a month.
hh:mm:ssHere mm sits between hh and ss, so it is minutes. If you write mm:ss alone, it is still minutes because ss follows. If you write mm by itself, you get the month number. When a format shows 01 where you expected 30, check whether the mm lost its neighbouring h or s.
Fractions of a second
Add a decimal point and zeros after ss to show fractions of a second.
hh:mm:ss.000A value of 0.000011574 (about one second) displays as 00:00:01.000. Excel only displays the digits you ask for, and the stored value keeps full precision.
Elapsed time with square brackets
A plain h format wraps at 24. If you total 30 hours and 15 minutes, h:mm shows 6:15, because 30 hours is one day plus 6 hours. The stored value is correct, but the display only shows the time-of-day part.
Square brackets tell Excel to show the total instead of the remainder.
[h]:mmThe same total (1.260416667) now displays as 30:15. The brackets work on all three units: [h] counts total hours, [m] counts total minutes, and [s] counts total seconds.
| Format | Value 1.260416667 shows |
|---|---|
| h:mm | 6:15 |
| [h]:mm | 30:15 |
| [m] | 1815 |
| [s] | 108900 |
Only the leftmost unit can use brackets. A format like [h]:[mm] is invalid.
Arithmetic with times
Because times are numbers, you can add and subtract them. A shift length is the end minus the start.
=B2-A2If A2 holds 9:00 and B2 holds 17:30, the result is 0.354166667. Format it as h:mm to see 8:30.
Shifts that cross midnight
If a shift starts at 22:00 and ends at 06:00, the subtraction gives a negative number. In the default 1900 date system, Excel cannot display a negative time and shows ##### instead. Wrap the subtraction in MOD to force a positive result.
=MOD(B2-A2,1)MOD with a divisor of 1 keeps only the fractional day, so a negative result becomes the correct positive duration. For 22:00 to 06:00 it returns 0.333333333, which is 8:00.
Converting a duration to decimal hours
Payroll often needs 8.5 rather than 8:30. Multiply the duration by 24 and format the result as Number.
=(B2-A2)*24The cell will probably inherit a time format from the inputs. If you see 8:30 or a strange time instead of 8.5, change the format to Number or General. To go the other way, divide by 24: =C2/24 converts 8.5 hours into a value that [h]:mm shows as 8:30.
Adding hours to a time
Use TIME to build the amount you add, so you never have to calculate the fraction yourself.
=A2+TIME(1,30,0)TIME wraps at 24 hours, so TIME(25,0,0) equals TIME(1,0,0). For larger amounts, divide: =A2+36/24 adds 36 hours.
Common problems
Several issues come up repeatedly with times.
- A total looks too small. The cell uses
h:mm. Change it to[h]:mm. - The cell shows #####. Either the column is too narrow, or the value is a negative time. Widen the column first. If it still shows #####, check whether the subtraction went below zero and use MOD or reorder the operands.
- A typed time is left-aligned and does not add. Excel stored it as text. This is usually caused by a stray space, an apostrophe, or a separator the locale does not recognise. The chapter on converting text covers the fix, and
TIMEVALUEis the usual tool. - Totals differ by a tiny amount. Times are floating-point fractions, so a sum may carry error in the last digits. A comparison like
=A1=B1can return FALSE for times that look identical. Round both sides:=ROUND(A1*86400,0)=ROUND(B1*86400,0)compares them to the nearest second. - A time prints with a date. If a calculation produces a value above 1, a format such as
m/d/yyyy h:mmshows the date part. Use a time-only format to hide it, or[h]:mmto show the full duration.
Putting it together
Consider a timesheet with start times in column A and end times in column B. Column C holds the duration, and column D holds decimal hours for payroll.
=MOD(B2-A2,1)Format column C as [h]:mm. In D2 enter =C2*24 and format D2 as Number with two decimals. A total row beneath column C uses =SUM(C2:C20) with the same [h]:mm format, so a week of 41.5 hours shows as 41:30 instead of wrapping to 17:30.
Exercise
A cell contains the total of five shifts, stored as 1.5625. It displays 13:30 with the format h:mm. What format shows the true total, and what does it display?
Show answer
Use [h]:mm. The value 1.5625 is 1 day and 13.5 hours, which is 37.5 hours in total. The h:mm format drops the whole day and shows only 13:30. The format [h]:mm shows 37:30.
Exercise
A night shift starts at 21:00 in A2 and ends at 05:30 in B2. The formula =B2-A2 shows #####. Write a formula that returns the correct duration, and a second formula that returns it as decimal hours.
Show answer
Use =MOD(B2-A2,1) for the duration, which is 8:30 when formatted as [h]:mm. For decimal hours use =MOD(B2-A2,1)*24, formatted as Number, which returns 8.5.