Sub topic 14
Text dates and common errors
This chapter assumes you can enter formulas, use cell references, and apply a number format. It covers the faults that most often break date formulas. Most trace back to one cause: a cell that looks like a date but isn't a serial number.
Spotting a text date
A text date is a string such as 2024-03-15 that Excel stores as characters, not as a serial number. Date functions and arithmetic then fail or give wrong results.
Signs of a text date:
- The value is left-aligned. Real dates are right-aligned by default.
- Changing the format to General leaves the text unchanged. A real date would turn into a number such as 45366.
=ISTEXT(A2)returns TRUE.
Text dates usually come from CSV imports, pasted web data, or entries with a leading apostrophe.
Converting text to real dates
DATEVALUE converts a date string to its serial number.
=DATEVALUE("2024-03-15")This returns 45366. Format the cell as a date to see it as one. Use the same function on a cell reference, as in =DATEVALUE(A2).
Strings in year-month-day order are the safest input. A string like 03/04/2024 is read according to your system's regional settings, so it may mean 3 April or March 4. If a workbook is shared across regions, rebuild the date with DATE from parts you extract yourself.
=DATE(LEFT(A2,4),MID(A2,6,2),RIGHT(A2,2))This works for text in the form 2024-03-15 and does not depend on locale.
Common errors and their causes
| Symptom | Likely cause | Fix |
|---|---|---|
| `#VALUE!` | An argument is text Excel cannot read as a date, such as `March 15th` | Clean the text, then use `DATEVALUE` or `DATE` |
| `#NUM!` from `DATEDIF` | The start date is later than the end date | Swap the arguments or guard with `IF` |
| `#####` in the cell | The column is too narrow, or the date result is negative | Widen the column and check the order of subtraction |
| A number such as 45366 | The cell has a General or Number format | Apply a date format |
| A date such as 14 Jan 1900 | A day count was formatted as a date | Format the result as General or Number |
| Dates off by four years and one day | Workbooks use different date systems | See below |
The last row has a specific cause. The 1904 date system counts from a different starting point than the 1900 system, and the two differ by 1462 days. If you paste dates between workbooks that use different systems, they shift by that amount. Check the setting under the workbook's calculation options and make both files match.
Guarding against bad input
Wrap a formula so a bad start date shows a message and does not return an error.
=IF(AND(ISNUMBER(A2),A2<=TODAY()),DATEDIF(A2,TODAY(),"Y"),"Check date")ISNUMBER is TRUE only for a real date or number, so text is caught before DATEDIF runs. The A2<=TODAY() test prevents the #NUM! error for future dates.
Exercise
Exercise
A2 contains the text 2024-02-29, left-aligned. Write a formula that returns the number of complete years from that date to today, and say why =DATEDIF(A2,TODAY(),"Y") might fail first.
Show answer
DATEDIF needs a real date, and A2 is text, so convert it first: =DATEDIF(DATEVALUE(A2),TODAY(),"Y"). For a locale-independent version, use =DATEDIF(DATE(LEFT(A2,4),MID(A2,6,2),RIGHT(A2,2)),TODAY(),"Y"). The original formula may return #VALUE! or give unreliable results because the start argument is a string and not a serial number.