Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Understanding Date and Time Formatting Codes.

Understanding Date and Time Formatting Codes

Written by Allen Wyatt (last updated June 28, 2023)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


7

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, displays 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, 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.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Changing the Default Highlighting Color

One of the tools that Word makes available on the Home tab of the ribbon is the Text Highlight tool. This functions ...

Discover More

Inserting Footnotes

Footnotes appear at the bottom (or foot) of each page. It is an easy task to insert a footnote at any point you desire, ...

Discover More

Summing Based on Part of the Information in a Cell

Excel provides a variety of tools that allow you to perform operations on your data based upon the characteristics of ...

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

More ExcelTips (ribbon)

Altering the Displayed Format of Numbers to the Nearest 100

Want information in a worksheet to be formatted and displayed as rounded to a power of ten? You may be out of luck, ...

Discover More

Can't Set Custom Format in VBA

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 More

Adding a Custom Format to those Offered by Excel

Adding a custom format to Excel is easy. Having that custom format appear in all your workbooks is a different story ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 2 + 2?

2024-09-29 12:23:16

Jeff C

The purpose of the square brackets is to allow the value to exceed its normal maximum. For example, you can't show '65' minutes in a cell using mm:ss, The largest value that format can show is 59:59. But if you use [m]:ss, you can display numbers larger than 59. You can also use [h]:mm to show values larger than 23:59.


2024-09-28 15:16:06

J. Woolley

@Agnitra Bhattacharjee
2.592673611 is the date-time serial number for 2 days, 14 hours, 13 minutes, and 27 seconds.
[h]:mm:ss converts that to 62:13:27 because 2 days, 14 hours is 48 + 14 = 62 hours.
[m]:ss converts 2.592673611 to 3733:27 because 62 hours, 13 minutes is 3733 minutes.


2024-09-28 00:16:59

Agnitra Bhattacharjee

Extremely helpful indeed however I am still confused about the function of the [ ] thought.


2024-06-28 12:34:12

Jonmoni das

Helpfull


2024-02-06 12:48:06

kiran

helpful


2021-04-22 10:51:21

J. Woolley

@Norm
See https://exceljet.net/custom-number-formats
and https://www.thespreadsheetguru.com/blog/excel-custom-number-format-rules
and https://customformats.com/


2021-04-21 22:56:24

Norm Thibodeau

I see some custom date codes in my spreadsheet include special characters. I have not been able to find any info on these special characters searching the web. I'd like to know what they mean and how/when to use them. Can you help? Here are some of the custom formats I see with special characters:
m/d/yy;@
[$-en-US]dddd, mmmm d, yyyy
_($* #,##0_);_($* (#,##0);_($* "-"_);_(@_)
The above use the following special characters:
;@
[$-en-US]
_($*
_);_


This Site

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.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.