Sub topic 14
Text dates and common errors
This chapter assumes you can enter formulas, use cell references such as A2, and apply a number format to a cell. It also assumes you know the serial number model from earlier in this tutorial: a date is a count of days, and a format only controls how that count is displayed.
Most date problems come from one cause. The cell does not hold a serial number at all. It holds text that looks like a date. This chapter shows how to spot that case, convert the text, and read the errors that date functions return.
What a text date is
A text date is a string of characters such as 2024-03-15 or 15.03.2023. Excel treats it like any other word, so none of the date functions can use it as a date.
Text dates usually arrive from CSV files, exports from other systems, copied web tables, or cells formatted as Text before the value was typed. Typing a date that your regional settings do not recognize also leaves it as text. For example, 15/03/2023 stays text when your system uses month/day/year order.
Three quick checks tell you what a cell holds:
| Check | Real date | Text date |
|---|---|---|
| Default alignment | Right | Left |
| `=ISNUMBER(A2)` | TRUE | FALSE |
| Format changed to General | Shows a number such as 45366 | Looks unchanged |
The last row is the check from earlier in this tutorial. If switching the cell to General does not reveal a serial number, the cell was never a date.
=ISNUMBER(A2)Alignment is only a hint, because someone can change it by hand. Use ISNUMBER when you need to be sure.
Converting text to real dates
You have several options. Choose by how predictable the text format is.
DATEVALUE and VALUE
DATEVALUE converts a date stored as text into a serial number.
=DATEVALUE("2024-03-15")With the cell formatted as General, this returns 45366. VALUE(A2) and the double unary --A2 do the same job for date text that Excel can parse.
These functions use your regional settings to decide what the text means. The string 03/04/2024 becomes 4 March on a month/day/year system and 3 April on a day/month/year system. A workbook can therefore give different answers on different computers without any error. Use these functions only when you know the text is ISO style (2024-03-15) or your own locale's format.
Rebuilding with DATE
When the layout is fixed, take the string apart and rebuild the date. This does not depend on any regional setting.
=DATE(LEFT(A2,4),MID(A2,6,2),RIGHT(A2,2))If A2 holds the text 2024-03-15, this returns 45366. The text pieces are coerced to numbers automatically. For text such as 15.03.2023 in day.month.year order, change the positions:
=DATE(RIGHT(A2,4),MID(A2,4,2),LEFT(A2,2))This is the most reliable method for imported data, because you state which part is the year, month and day.
Text to Columns
For a whole column, select it, then choose Data, Text to Columns. Click Next twice and, in the final step, pick a Date format and the order such as DMY. This converts the cells in place. It is a one-time fix, not a formula, so repeat it when you paste in new data.
Hidden characters
Sometimes a text date will not convert even though it looks right. The cause is often a leading or trailing space or a non-breaking space, which web pages commonly add. TRIM removes ordinary spaces but not the non-breaking space, character 160.
=DATEVALUE(TRIM(SUBSTITUTE(A2,CHAR(160)," ")))Reading the common errors
Date functions fail in a small number of ways. The table lists each symptom with its usual cause.
| What you see | Usual cause | Fix |
|---|---|---|
| `45366` instead of a date | The cell is formatted as General | Apply a date format |
| `#####` | The column is too narrow, or the result is a negative date | Widen the column; check the subtraction order |
| `#VALUE!` | An argument is text Excel cannot read as a date | Convert it with DATE or DATEVALUE |
| `#NUM!` from DATEDIF | The start date is later than the end date | Swap the arguments or guard with IF |
| `#NUM!` from EDATE or EOMONTH | The result would fall before the first valid date | Check the inputs |
| A date years in the wrong century | A two-digit year was interpreted by Excel's cutoff rules | Enter four-digit years |
| Dates off by 1462 days | The workbooks use different date systems | Align the 1900 and 1904 settings |
The ##### display
Two different problems produce hash marks. If the date is valid but the column is too narrow, widening the column fixes it. In the 1900 date system, a negative result also displays as hash marks, because a date before day 1 cannot be shown. A subtraction written in the wrong order is the common cause:
=DATE(2024,1,1)-DATE(2024,3,1)This returns -60. Formatted as a date, it shows hash marks. Formatted as General, it shows -60. If you wanted a count of days, format the cell as General or Number and put the later date first.
#VALUE! from text
Arithmetic and most date functions return #VALUE! when an argument is text that Excel cannot interpret.
=EDATE(A2,1)If A2 holds 15.03.2023 on a system that expects slashes, this returns #VALUE!. The cell is not a date, so convert it first. Do not wrap the result in IFERROR to hide the problem. That silences the error and leaves blank or wrong values in your report.
Excel sometimes converts text for you. For example, ="2024-03-01"-"2024-01-01" returns 60 because arithmetic coerces ISO-style strings. That is helpful in tests but unsafe in a real workbook, because the same formula can fail with differently formatted text or on another computer.
#NUM! from DATEDIF
DATEDIF returns #NUM! when the start date is later than the end date. This happens with age formulas when a start date is in the future.
=IF(A2>TODAY(),"Not started",DATEDIF(A2,TODAY(),"Y"))DATEDIF is also missing from the formula autocomplete list and the function wizard. It still works when you type it in full. A #NAME? error here usually means a typing mistake in the name, not that the function is unavailable.
Dates that look right but compare wrong
A real date can still give a surprising result when it carries a time. Recall that the time of day is the fractional part of the serial number. A cell holding 15 March 2024 at 9:30 is 45366.3958, and it is not equal to 45366.
=A2=TODAY()This returns FALSE if A2 contains a time, even when the calendar date is today. Compare whole days instead:
=INT(A2)=TODAY()The same issue affects counts. COUNTIF and lookups on a date column miss rows whose values include a time unless you strip the fraction with INT.
Two systems, two results
The 1900 and 1904 date systems differ by 1462 days. Copying dates between workbooks that use different systems shifts each date by four years and one day. Excel normally adjusts on paste, but links and imported values may not be adjusted. If dates look about four years off, check File, Options, Advanced, and the "Use 1904 date system" setting in both workbooks.
Dates before 1 January 1900 cannot be stored as real dates in the 1900 system. Excel keeps them as text, so they will not work in arithmetic or in DATEDIF.
A diagnostic routine
Work through the cause in this order when a date formula misbehaves.
- Test the input with
ISNUMBER. If it is FALSE, fix the text first. - Switch the result cell to General and read the serial number. If it is a sensible number, the problem is only formatting.
- Look for a time fraction when comparing dates for equality.
- Check the date system if results are off by 1462 days.
- Check the order of arguments.
DATEDIFand subtraction both need the earlier date first.
Putting it together
Suppose column A holds start dates imported as text in 2024-03-15 form. This formula converts each one, then reports whole years of tenure, and returns a readable message if the text is not a date.
=IFERROR(DATEDIF(DATE(LEFT(A2,4),MID(A2,6,2),RIGHT(A2,2)),TODAY(),"Y"),"Check date text")The IFERROR here is deliberate and narrow. It labels bad rows for review, where a bare IFERROR(...,0) would hide them. A start date in the future also lands in the "Check date text" branch, since DATEDIF returns #NUM!. That is acceptable for a review column, but the label should be accurate for your data. Use the IF(A2>TODAY(),...) guard from earlier if you need to separate the two cases.
Exercise
Cell A2 holds the text 20240315 (year, month, day with no separators). Write a formula that returns a real date, and explain why ISNUMBER(A2) would be a poor test of whether the cell is a date once it is typed with digits only.
Show answer
Use =DATE(LEFT(A2,4),MID(A2,5,2),RIGHT(A2,2)), which returns 45366 in General format. The poor test is that Excel may store 20240315 as the number twenty million and so ISNUMBER returns TRUE, yet it is not a date serial. A real date serial for current dates is near 45000, so a number that large is a number, not a date. Check the value's size as well as its type, or convert it with the DATE formula.
Exercise
A2 holds a real date with a time, 15 March 2024 14:00. The formula =A2=DATE(2024,3,15) returns FALSE. Why, and what is the fix?
Show answer
A2 is 45366.5833, and DATE(2024,3,15) is 45366, so the values are not equal. Remove the time with INT: =INT(A2)=DATE(2024,3,15) returns TRUE.