Written by Allen Wyatt (last updated May 3, 2025)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Excel in Microsoft 365
In Excel, dates and times are stored internally as numbers. These are only converted to legible dates and times when you format the cell using a date or time format. You can use one of Excel's pre-defined date and time formats or you can create your own custom format.
Regardless of which approach you take, you use the Number tab of the Format Cells dialog box (display the Home tab of the ribbon, click the small icon at the bottom-right of the Number group, then make sure the Number tab is displayed.) The Date, Time, and Custom options all appear at the right of the dialog box. (See Figure 1.)
Figure 1. The Number tab of the Format Cells dialog box.
If you create a custom format for your dates and times, you need to become conversant in the codes you can use to define those formats. The following table lists the formatting codes that are specific to dates and times. You use these codes when you are creating a custom display format (display the Home tab of the ribbon, click the small icon at the bottom-right of the Number group, then choose Custom in the Category list).
Symbol | Meaning | |
---|---|---|
m | Displays the month or minutes as a number without a leading 0 | |
mm | Displays the month or minutes as a number with a leading 0 | |
mmm | Displays the month as abbreviated text (Jan, Feb, Mar, and so on) | |
mmmm | Displays the month as text (January, February, March, and so on) | |
d | Displays the day of the month as a number without a leading 0 | |
dd | Displays the day of the month as a number with a leading 0 | |
ddd | Displays the day of the week as abbreviated text (Sun, Mon, Tue, and so on) | |
dddd | Displays the day of the week as text (Sunday, Monday, Tuesday, and so on) | |
yy | Displays the year with two digits | |
yyyy | Displays the year with four digits | |
h | Displays the hour without a leading 0 | |
hh | Displays the hour with a leading 0 | |
s | Displays the seconds without a leading 0 | |
ss | Displays the seconds with a leading 0 | |
[ ] | When surrounding hours, minutes, or seconds place holders, allows the display of hours greater than 24 or minutes and seconds greater than 60 | |
AM am PM pm A a P p | Uses a 12-hour clock, displaying AM or PM as specified | |
\ | Forces display of the following character | |
. (period) | The decimal point. | |
"text" | Displays the text within the quotes. |
To understand better the effect of the date and time codes, take a look at the following information, which shows several common date and time formats and how they affect numbers.
Category | Format | Value | Displayed As | |||
---|---|---|---|---|---|---|
Date | m/d/yy | 34369 | 2/4/94 | |||
d-mmm-yy | 34409 | 16-Mar-94 | ||||
Time | h:mm AM/PM | 0.654166667 | 3:42 PM | |||
[h]:mm:ss | 2.592673611 | 62:13:27 |
Notice that the numbers shown in the value column of these examples are the internal values stored by Excel for dates and times.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (8319) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Understanding Date and Time Formatting Codes.
Create Custom Apps with VBA! Discover how to extend the capabilities of Office 365 applications with VBA programming. Written in clear terms and understandable language, the book includes systematic tutorials and contains both intermediate and advanced content for experienced VB developers. Designed to be comprehensive, the book addresses not just one Office application, but the entire Office suite. Check out Mastering VBA for Microsoft Office 365 today!
You can, in a macro, specify a custom format for a range of cells. If the custom format doesn't seem to "stick" (so to ...
Discover MoreWant some dashes automatically added in values you display in a cell? It may be trickier to develop a custom format than ...
Discover MoreWhen you create custom formats for your data, Excel provides quite a few ways you can make that data look just as you ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2025-05-03 21:00:01
J. Woolley
It is interesting to note you can display elapsed time (duration) in years, months, days, hours, minutes, and seconds using the custom format
y, m, d, h, m, s
but the result for months and days is generally incorrect.
My Excel Toolbox includes the following function:
=TimeDif(Start, Finish, [Approximate], [Conversational])
Start and Finish must be numeric or text dates or times or date/time combinations. TimeDif returns the difference between Start and Finish as text, which can optionally be exact, approximate, or conversational. The optional arguments are FALSE by default, yielding an exact result.
See https://sites.google.com/view/MyExcelToolbox/
2025-05-03 16:55:48
Tomek
I once encountered a problem when I needed to display only minutes, not any other part of the time date. I just needed to see number of minutes that passed since the previous top of the hour. Because Excel uses "m" for both minutes and months there was no way to achieve this just by formatting.
If I wanted minutes and seconds I could use m:s and it would work. Granted, my need was very eccentric, and this is not likely to cause problems for anybody, but it could be easily overcome if Microsoft use capital M for months and lowercase m for minutes, like it is done in Word.
2025-05-03 08:08:57
Alex Blakenburg
Borrowing from Power Query terminology, I like to think of hh:mm and h:mm etc as being "Time" format and [hh}:mm and [h]:mm as being "Duration" format (difference in time).
2025-05-03 05:57:27
Kiwerry
For those who need fractions of a second, this was addressed in
https://excelribbon.tips.net/T007557_Formatting_for_Hundredths_of_Seconds.html.
An example would be [h]:mm:ss.000 If you try to use more zeros in the format (to display smaller increments of time), Excel 365 balks. The smallest increment you can display using custom formats is a thousandth of a second.
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2025 Sharon Parq Associates, Inc.
Comments