Sub topic 2
Format versus value: seeing the serial number
The previous chapter introduced the idea that Excel stores a date as a count of days. This chapter covers the next step: a cell has a stored value and a separate number format that controls how that value looks. Most date confusion in Excel comes from mixing up these two things.
This chapter assumes you can enter formulas, use cell references such as A2, and open the Format Cells dialog (Ctrl+1 on Windows).
Two layers in every cell
A cell holds two independent things:
- The value is what Excel calculates with. For a date, it is a serial number such as 45000.
- The number format is a display rule. It decides how the value is drawn on screen or on paper.
Changing the format never changes the value. A formula that refers to the cell always receives the stored number, whatever the cell shows.
Seeing the serial number
Enter this formula in a cell:
=DATE(2023,3,15)Excel usually applies a date format to the cell automatically, so you will probably see something like 15/03/2023 or 3/15/2023, depending on your regional settings. To see the stored value, select the cell and switch it to General. Either of these works:
- Press Ctrl+Shift+~ (tilde) to apply General.
- Open Home > Number Format drop-down and choose General.
The cell now shows 45000. Nothing in the cell was recalculated. Only the display rule changed. Switch the format back to a date format and the date returns.
The same value under different formats
The table shows serial 45000 under several formats.
| Number format code | Displayed result |
|---|---|
| General | 45000 |
| #,##0 | 45,000 |
| 0.00 | 45000.00 |
| d/m/yyyy | 15/3/2023 |
| dd-mmm-yy | 15-Mar-23 |
| yyyy-mm-dd | 2023-03-15 |
| mmm | Mar |
| dddd | Wednesday |
| dddd d mmmm yyyy | Wednesday 15 March 2023 |
You can type any of these codes in Format Cells > Number > Custom. The cell's value stays 45000 in every row.
Reading format codes
A few letters do most of the work:
dis the day number,ddpads it to two digits,dddgives the short weekday name, andddddgives the full name.mis the month number,mmpads it,mmmgives the short month name, andmmmmgives the full name.yyis a two-digit year andyyyyis a four-digit year.
Note that m means month when it stands alone or follows a date code, but it means minutes when it directly follows h or precedes s. So h:mm shows minutes, while d/m/yyyy shows a month.
Format names and code letters can vary by language and regional settings. Some language versions use other letters for day, month, and year. The default short date order (day first or month first) also follows the system locale. A workbook that displays 03/04/2023 for one user may display it differently for another, even though the stored value is the same.
What happens when you apply the wrong format
Format mismatches are the most common reason a date formula looks broken. They fall into two directions.
A date shown as a number
You calculate a deadline, such as =A2+30, and the result appears as 45030 instead of a date. The value is correct, but the cell has General format. Apply a date format and it displays properly.
A number shown as a date
You subtract two dates and get something like 14-Feb-00 or 01/02/1900. The formula result is a day count, but the cell has a date format. For example:
=DATE(2024,3,1)-DATE(2024,1,1)The result is 60 days. If the cell is formatted as a date, Excel interprets 60 as a position on the calendar and shows an early 1900 date. For any count of days, use General or Number format. A small value such as 45 shows as 14-Feb-1900 in a date-formatted cell, because serial 45 is the 45th day of the 1900 calendar.
Hash signs and negative values
If a cell shows #######, one of two things is usually true:
- The column is too narrow for the formatted text. Widen the column.
- The value is negative and the format is a date or time format. Excel cannot draw a negative date, so it fills the cell with hash signs. This often happens when you subtract a later date from an earlier one while the result cell is formatted as a date.
Checking whether a cell holds a real date
A date that Excel recognizes as a date is a number. A date that came in as text, for example from a CSV import, only looks like one. The display alone cannot tell you which you have, so test the value:
=ISNUMBER(A2)This returns TRUE when A2 holds a real number (including a real date) and FALSE when it holds text. Clues that a date is text include left alignment (numbers align right by default), a leading apostrophe in the formula bar, and a format change having no visible effect. The chapter on text dates and common errors covers how to convert them.
Format inside a formula: the TEXT function
Sometimes you want a date to appear inside a sentence. Concatenation exposes the two-layer model sharply. The & operator joins text, so Excel converts the date to text first, and it uses the raw number:
="Due: "&A2If A2 holds 15 March 2023, this returns Due: 45000. The cell's number format does not carry into the formula result. To control how the date is written, use TEXT with a format code:
="Due: "&TEXT(A2,"d mmm yyyy")This returns Due: 15 Mar 2023. TEXT takes the same codes as the Custom format dialog, so everything in the table above works inside it.
Trade-offs of TEXT
TEXT is useful for labels, but it has costs:
- The result is text, not a date. You cannot add days to it or compare it with other dates until you convert it back.
- Format codes inside TEXT are interpreted in the language of your Excel installation. A workbook that uses
"dd/mm/yyyy"may display wrong results or odd letters when opened in another language version. - If you only need the date to look different, change the cell's number format instead. This keeps the value numeric.
Copying, pasting, and the value layer
Because the format and value are separate, copy and paste has options that affect each one:
- A normal paste copies both the value (or formula) and the format.
- Paste Special > Values copies the displayed result as a value and leaves the destination format unchanged. If the destination is General, a pasted date appears as a serial number.
- Paste Special > Formats copies only the display rule and leaves the destination's value alone.
If you paste values and see 45000, the data is intact. Apply a date format to the destination.
Checking your understanding
You can inspect any cell with these steps:
- Click the cell and read the formula bar. For a typed date, it usually shows the date in your short format. For a formula, it shows the formula.
- Press Ctrl+Shift+~ to show the General value, then Ctrl+Z to undo.
- Use
=ISNUMBER(A2)to confirm that the value is numeric. - Use
=A2+0in another cell, formatted as General, to see the serial number without changing A2 at all.
The last option is useful in shared workbooks, where you should not change a cell's format just to look at it.
Exercise
Cell A2 contains a real date, 15 March 2023, formatted as dd-mmm-yy. A colleague enters ="Due: "&A2 in B2 and it displays Due: 45000. Why does this happen, and what formula would display Due: 15-Mar-23 instead?
Show answer
The & operator converts A2 to text using its stored value, not its number format, so it joins the serial number 45000. Use TEXT to apply a format code: ="Due: "&TEXT(A2,"dd-mmm-yy").
Exercise
In a workbook, C2 contains =DATE(2024,3,1)-DATE(2024,1,1) and shows 29-Feb-00-style output instead of 60. What is wrong, and how do you fix it without changing the formula?
Show answer
The formula result is 60, a count of days, but C2 has a date format, so Excel draws 60 as a calendar date in early 1900. Change the cell's number format to General (Ctrl+Shift+~) or Number, and it shows 60.