Sub topic 11
Date formats and date codes
This chapter assumes you know how to open Format Cells and that Excel stores a date as a serial number, a count of days since the start of its date system. Here you will learn how Excel turns that serial number into text you can read, and how to control the result with date codes.
What a date format does
A date format changes only the display. The cell below holds the serial number 45356 whether it shows 03/05/2024, Tue 5 Mar or 45356. Formulas, sorting and date arithmetic always use the number.
Suppose A1 holds =DATE(2024,3,5). Each of these formats shows the same stored value differently:
| Format code | Displayed result |
|---|---|
| `m/d/yyyy` | 3/5/2024 |
| `dd-mmm-yy` | 05-Mar-24 |
| `yyyy-mm-dd` | 2024-03-05 |
| `dddd, mmmm d, yyyy` | Tuesday, March 5, 2024 |
| `mmm yyyy` | Mar 2024 |
The date codes
Excel builds a date display from letter codes. Each letter stands for one part of the date, and the number of repeated letters sets the style.
| Code | Meaning | Example for 5 March 2024 |
|---|---|---|
| `d` | Day without a leading zero | 5 |
| `dd` | Day with two digits | 05 |
| `ddd` | Abbreviated weekday name | Tue |
| `dddd` | Full weekday name | Tuesday |
| `m` | Month number without a leading zero | 3 |
| `mm` | Month number with two digits | 03 |
| `mmm` | Abbreviated month name | Mar |
| `mmmm` | Full month name | March |
| `mmmmm` | First letter of the month | M |
| `yy` | Two-digit year | 24 |
| `yyyy` | Four-digit year | 2024 |
Two details save trouble. First, mmmmm (five m's) gives only the first letter, so March and May both show M. Use it for compact chart labels, not for data people must read. Second, there is no code for the day of the year or the week number. For those you need a formula.
You enter these codes in the Custom category of Format Cells. The format yyyy-mm-dd is the ISO order and sorts correctly even when it is copied as text.
dddd, mmmm d, yyyyMonth or minute?
The letter m is used for both months and minutes. Excel decides by position. If the m or mm comes directly after an h or hh, or directly before an s or ss, it means minutes. In every other position it means months.
This rule explains why hh:mm shows a time and mm/dd shows a date. It also explains a common failure. If you write mm with other text between it and the h, Excel reads it as a month. In h "hours" mm "minutes", the quoted text breaks the adjacency, so the second code shows a month number. In that case, split the display across cells or build the text with a formula.
Literal text and separators
Excel displays these characters as they are, without quotes: - / . , : space and a few others such as $ + ( ) < > =. Any other letter must be quoted or escaped with a backslash, because many letters are codes. A bare o or f can cause an error, and a bare d or y silently becomes part of the date.
dddd d "of" mmmm yyyyFor 5 March 2024 this shows Tuesday 5 of March 2024. The quotes around of stop Excel from reading those letters as codes. A single character can use a backslash instead, as in d\t\h (which shows 5th for every day, so it is only a formatting trick, not grammar).
Built-in formats and the asterisk
The Date category in Format Cells lists built-in formats. Two of them, Short Date and Long Date, are tied to your system's regional settings. Excel marks them internally with an asterisk. In the list they appear with a leading *, as in *3/14/2012. If you change the date order in Windows or macOS, cells with an asterisk format change with it. Formats without an asterisk stay the same on every computer.
This is a trade-off. An asterisk format shows each viewer their own local style, which suits a shared report. A fixed custom format such as yyyy-mm-dd looks identical for everyone, which suits exports and files shared between countries.
The keyboard shortcut Ctrl+Shift+# applies a date format with day, month and year (d-mmm-yy). It is a fast way to confirm that a cell holds a real date: if the cell turns into a readable date, the stored value was a number.
Dates in formulas
A date format applies only to cells. When a formula joins a date into text, the formula returns text, and no cell format can change it. Use TEXT to choose the pattern.
=TEXT(A1,"yyyy-mm-dd")This returns 2024-03-05 as text. Format codes inside TEXT can depend on the language of your Excel installation. In a German installation, for example, the year code is JJJJ and the day code is T, so a formula copied between language versions may return the wrong pattern or an error. The TEXT function gets its own chapter, so treat this as a warning for now.
To turn a date written as text into a usable serial number, use DATEVALUE:
=DATEVALUE("2026-11-27")The ISO form yyyy-mm-dd is the safest input because every regional setting reads it the same way. A string such as 03/04/2024 is ambiguous: it is 4 March in the United States and 3 April in most of Europe.
Common problems
- The cell shows a number such as 45356. The cell has General or Number format. Apply a date format. The value is already a valid date.
- The cell shows
####. Either the column is too narrow for the formatted text, or the value is a negative number, which a date format cannot display. Widen the column first. - The date is left-aligned and the format does not change. The cell holds text, not a date. Applying a format to text does nothing. Convert it with DATEVALUE or Text to Columns.
- Dates before 1 January 1900 do not work. Excel's default date system starts at 1900, so earlier dates can only be stored as text.
- Two-digit years are guessed. If you type
1/2/30, Excel reads the year as 2030. Years 00 to 29 become 2000 to 2029, and years 30 to 99 become 1930 to 1999. Type four digits to avoid surprises.
Choosing a date format
Pick the format by who will read the cell and where the file will go.
- For internal dashboards, use a built-in asterisk format so each reader sees their regional style.
- For files sent across countries, use
yyyy-mm-ddord mmm yyyy. The month name removes any day/month confusion. - For labels in charts, use
mmmormmm yy, and only usemmmmmwhen space is very tight. - For text inside sentences, use TEXT in a formula and test it on the language version your readers use.
Exercise
Cell A1 holds the date 5 March 2024. You want it to display as Tue, 05 Mar 2024. Which custom format code do you enter, and how would you use a code to show the month as 03 and the minutes of a time as 07 in the same format yyyy-mm-dd hh:mm?
Show answer
Use ddd, dd mmm yyyy. The comma and spaces are literal characters that Excel displays without quotes. In yyyy-mm-dd hh:mm, the first mm follows yyyy- and is not next to h or s, so it is the month (03). The second mm comes directly after hh:, so it means minutes (07). Excel decides purely by position.