Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Office 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.
by Allen Wyatt
(last updated October 12, 2019)
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).
|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.
|Time||h:mm AM/PM||0.654166667||3:42 PM|
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 Office 365. You can find a version of this tip for the older menu interface of Excel here: Understanding Date and Time Formatting Codes.
Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!
Custom formats can be very powerful in Excel, but not every formatting scenario can be addressed through the use of a ...Discover More
Excel, by default, displays numbers with a leading zero, if they are less than 1. Here's how you can get rid of those ...Discover More
Want a quick and easy way to hide the information in a cell? You can do it with a simple three-character custom format.Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
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.