Convert Date to Text: Formats & Excel Tips
The calculator for this page is switched off while it is checked. The formula is below, and the worked example in the article shows how to use it by hand.
To convert a date to text means turning a date value (like 2024-03-15) into a string of characters (like “15 March 2024”) so it can be used in a document, filename, or report without changing its appearance. You can do this in spreadsheet software, programming languages, and online tools, and the method you choose depends on the format you need and the tool you are using.
Why Convert a Date to Text?
Dates are stored as numbers in most software, which is great for calculations but problematic when you need a fixed, human-readable label. Converting a date to text is useful for:
- Creating filenames that sort chronologically (e.g.,
2024-03-15_report.txt) - Generating formatted dates for letters, certificates, or invoices
- Preventing date values from changing when shared between systems with different locale settings
- Extracting a readable date from a timestamp for display purposes
Without conversion, a date like 03/15/2024 might be misinterpreted as March 15 or 3 May depending on the reader’s country.
How Date-to-Text Conversion Works
Internally, most systems store dates as serial numbers. For example, in Excel, January 1, 1900 is serial number 1, and each day adds 1. When you convert to text, the software takes that serial number and applies a format mask to produce a string. The mask defines the order and style of day, month, and year components.
Common format codes include:
YYYY– four-digit year (2024)YY– two-digit year (24)MM– two-digit month (03)MONorMMM– abbreviated month name (Mar)MONTHorMMMM– full month name (March)DD– two-digit day (15)
In programming languages like Python or JavaScript, you use built-in functions to extract parts of a date object and then concatenate them into a string. For instance, in Python: date.strftime("%d %B %Y") produces “15 March 2024”.
Excel: The TEXT Function
In Excel, the most direct method is the TEXT function:
TEXT(value, format_text)
For example, if cell A1 contains 2024-03-15, then =TEXT(A1, "dd mmmm yyyy") returns “15 March 2024”. You can also use =TEXT(A1, "yyyy-mm-dd") for an ISO-style text date. The result is a text string, so it won’t be recognized as a date in calculations.
Another method is the Text to Columns wizard (Data tab > Text to Columns), which can convert a column of dates to text with a chosen format. However, the TEXT function is more flexible for individual cells.
Google Sheets: TEXT and TO_TEXT
Google Sheets has a similar TEXT function: =TEXT(A1, "dd mmmm yyyy"). There is also TO_TEXT, which simply converts a value to plain text using the cell’s current display format. For example, =TO_TEXT(A1) returns the date as it appears in the cell (e.g., “3/15/2024” if that is the format).
If you need a specific format, use TEXT with a format string. Google Sheets uses the same format codes as Excel for dates.
Programming Languages: Python and JavaScript
In Python, the datetime module provides strftime():
from datetime import datetime
d = datetime(2024, 3, 15)
print(d.strftime("%d %B %Y")) # 15 March 2024
In JavaScript, you can use toLocaleDateString() with options:
const d = new Date(2024, 2, 15); // month is 0-indexed
console.log(d.toLocaleDateString("en-GB", { day: "numeric", month: "long", year: "numeric" })); // 15 March 2024
Both methods give you full control over the output format.
Common Mistakes and Pitfalls
- Locale differences: Dates like
03/04/2024are ambiguous. Always specify the format explicitly. - Month indexing in JavaScript: Months are 0-based (January = 0), so
new Date(2024, 2, 15)is March 15, not February 15. - Time zone shifts: When converting timestamps to dates, time zone differences can change the date. For example, converting a UTC timestamp to local time may shift the date backward or forward.
- Text dates are not sortable as dates: If you convert to text like “15 March 2024”, sorting alphabetically will not put them in chronological order. Use ISO format (
2024-03-15) if you need text that sorts correctly.
Alternatives to Converting to Text
If your goal is just to display a date in a different format, you don’t necessarily need to convert it to text. In Excel or Google Sheets, you can change the cell’s number format to display the date however you like, while keeping the underlying value as a real date. This preserves the ability to do date arithmetic.
For filenames or data exchange, though, a text conversion is often unavoidable. In those cases, choose a format that is unambiguous and sortable, such as YYYY-MM-DD (ISO 8601).
Frequently Asked Questions
How do I convert a date to text in Excel without losing the format?
Use the TEXT function: =TEXT(A1, "dd mmmm yyyy"). This returns a text string that displays exactly as specified. The original date in cell A1 remains unchanged.
Why does my date convert to a number like 45200?
That is the underlying serial number that Excel uses to store dates. If you see a number, the cell is formatted as General or Number. To convert it to text, use the TEXT function with a format code, or change the cell format to a date format before converting.
Can I convert a date to text in Google Sheets?
Yes, use =TEXT(A1, "dd mmmm yyyy") or =TO_TEXT(A1). The TEXT function gives you full control over the format.
What is the best format for storing dates as text?
ISO 8601 format (YYYY-MM-DD) is recommended because it is unambiguous, sorts chronologically as text, and is widely recognized internationally.
How do I convert a date to text in Python?
Use date.strftime("%d %B %Y") for a format like “15 March 2024”. Replace the format codes as needed.
Does converting a date to text affect calculations?
Yes. Once a date is text, Excel and Sheets will not treat it as a date in calculations. If you need to perform date arithmetic, keep the original date value and use a separate cell for the text version.
Related
Formula used
in d | Date (YYYY-MM-DD) | - | 2024-03-15 | 0 out text | Text date | - | d | 0
Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.