Sub topic 8
Converting between text and dates
This chapter assumes you can enter formulas, use relative and absolute references, and apply number formats from the Format menu. It also assumes you know that Sheets stores a date as a serial number, which is a count of days. Here the focus is the boundary between text and real date values: turning text into dates, turning dates into text, and the errors that come from mixing them up.
Why the boundary matters
A cell can show 2026-11-28 and still hold plain text. Date functions such as YEAR, EDATE and subtraction need a number. Text is not a number, so they return #VALUE! or silently give wrong results.
Going the other way has its own trap. The TEXT function turns a date into a string. That is useful for labels, but the result can no longer be used in date arithmetic.
Recognizing text that looks like a date
Check before you convert. Three signs show that a cell holds text:
- The value is left-aligned. Real dates are right-aligned by default.
=ISNUMBER(A2)returnsFALSE.=ISTEXT(A2)returnsTRUE.
=ISNUMBER(A2)Changing the cell's number format does not convert text. Format controls only how a number is displayed, so a text cell stays text under any format. Conversion needs a formula, or a re-entry of the value that Sheets then parses.
DATEVALUE: text to a date value
DATEVALUE reads a date written as text and returns its serial number.
=DATEVALUE("2026-11-28")The result is 46354, the day count for 2026-11-28. The cell may display it as a date or as a bare number, depending on the format it already has. If you see 46354, apply a date format from Format > Number. The value is already correct.
DATEVALUE also accepts a cell reference:
=DATEVALUE(A2)Note these behaviors:
- If the text includes a time, such as
"2026-11-28 14:30",DATEVALUEreturns only the whole-day part and drops the time. - If the text cannot be read as a date in the current locale, the result is
#VALUE!. VALUE(A2)also converts date text to a serial number, but it keeps the time part. Use it when you want the full date-time.
TIMEVALUE: text to a time of day
TIMEVALUE does the same for times. It returns a fraction of a day between 0 and 1.
=TIMEVALUE("14:30")This returns about 0.6041667, which is 14.5 hours divided by 24. Format the cell as Time to see 14:30:00.
To combine separate date text and time text into one date-time value, add the two results:
=DATEVALUE(A2) + TIMEVALUE(B2)Why locale decides the result
When Sheets parses text, it follows the spreadsheet's locale (File > Settings). That choice matters for ambiguous formats.
| Text | Locale United States | Locale United Kingdom |
|---|---|---|
| `03/04/2026` | March 4, 2026 | 3 April 2026 |
| `13/04/2026` | `#VALUE!` (no month 13) | 13 April 2026 |
| `2026-04-03` | April 3, 2026 | 3 April 2026 |
The ISO form yyyy-mm-dd is read the same way in every locale, so it is the safest text format to store or import. A day/month/year string such as 13/04/2026 fails under a US locale because there is no month 13. An ambiguous string such as 03/04/2026 is worse, because it parses without error and gives the wrong date.
Shared sheets can break this way. If a colleague's locale differs from yours, the same formula can return a different date for them.
Building dates from text parts
When the text format is fixed but not something your locale reads, skip DATEVALUE. Cut the text into pieces and pass them to DATE. DATE accepts numeric text for its arguments and builds a real date without any locale parsing.
For compact text such as 20261128:
=DATE(LEFT(A2, 4), MID(A2, 5, 2), RIGHT(A2, 2))For dotted text such as 28.11.2026, split on the separator and reorder the parts:
=DATE(INDEX(SPLIT(A2, "."), 1, 3), INDEX(SPLIT(A2, "."), 1, 2), INDEX(SPLIT(A2, "."), 1, 1))SPLIT returns the pieces across a row. INDEX(..., 1, 3) takes the third piece (the year), then the second (the month), then the first (the day). Because you name each part explicitly, the result does not depend on locale.
Cleaning text before converting
Imported data often has invisible problems that make DATEVALUE fail on text that looks right. Two common ones are extra spaces and non-breaking spaces (character code 160, which TRIM does not remove):
=DATEVALUE(TRIM(SUBSTITUTE(A2, CHAR(160), " ")))The inner SUBSTITUTE replaces non-breaking spaces with normal ones. TRIM then removes leading, trailing and repeated spaces.
TEXT: a date to formatted text
TEXT takes a value and a pattern, and returns a string.
=TEXT(A2, "yyyy-mm-dd")Common patterns:
| Pattern | Example result for 2026-11-28 14:30 |
|---|---|
| `yyyy-mm-dd` | 2026-11-28 |
| `dd/mm/yyyy` | 28/11/2026 |
| `mmm d, yyyy` | Nov 28, 2026 |
| `mmmm` | November |
| `dddd` | Saturday |
| `hh:mm` | 14:30 |
| `h:mm AM/PM` | 2:30 PM |
In a pattern, mm means month when it stands with date parts and minutes when it follows hours (hh:mm). Keep the pattern in quotes.
TEXT is the right tool when you join a date into a sentence. A bare date in a join is converted to its serial number:
="Due: " & A2This produces Due: 46354, not a readable date. Wrap the date:
="Due: " & TEXT(A2, "mmm d, yyyy")Month names produced by TEXT follow the spreadsheet locale. Patterns such as dddd give different language output in different locales.
Converting a whole column
Apply a conversion to every row with ARRAYFORMULA. Guard against blank rows, otherwise DATEVALUE("") produces errors:
=ARRAYFORMULA(IF(A2:A = "", "", DATEVALUE(A2:A)))Place this once in the header-adjacent cell, such as C2. Do not fill it down, because it already fills the column.
To keep going when some rows are unreadable, wrap the conversion with IFERROR and return a marker you can filter on:
=ARRAYFORMULA(IF(A2:A = "", "", IFERROR(DATEVALUE(A2:A), "check")))Choosing a method
Common errors
#VALUE!fromDATEVALUE. The text is not a valid date in the current locale, or it has hidden characters. Test with the cleaning formula above, and check whether the day and month are swapped.- A date shows as
46354. The conversion worked but the cell has a number format. Apply a date format. - A date shifts by a day or the wrong month. The text was read under a different locale than the one its author used. Rebuild it with
DATEand explicit parts. - Arithmetic on a
TEXTresult fails.TEXTreturns a string. Keep the original date in one column and useTEXTonly in a display or label column. - A time disappears.
DATEVALUEremoves the time part. UseVALUE, or addTIMEVALUE.
Exercise
Column A holds the text 20261128, 20270105 and 20271231. Write one formula in B2 that converts all of column A to real dates, leaves blank rows empty, and does not depend on the spreadsheet locale. Then write a formula in C2 that shows the date in B2 as text like Nov 28, 2026.
Show answer
In B2: =ARRAYFORMULA(IF(A2:A = "", "", DATE(LEFT(A2:A, 4), MID(A2:A, 5, 2), RIGHT(A2:A, 2)))). It builds each date from explicit year, month and day parts, so no locale parsing is involved. Format column B as a date. In C2: =TEXT(B2, "mmm d, yyyy"). C2 is text, so use B2 for any later date arithmetic.
Exercise
Cell A2 holds 05/06/2026 as text. Explain why =DATEVALUE(A2) can give two different dates on two machines, and name one way to remove the problem.
Show answer
DATEVALUE reads the text using the spreadsheet's locale. Under a US locale the result is May 6, 2026. Under a UK locale it is 5 June 2026. To remove the ambiguity, rewrite the source data as yyyy-mm-dd, or split the text and build the date with DATE using explicit day, month and year parts.