Excel Function: TEXT
Purpose
The TEXT function converts either a numeric, date or time value to a text value, and changes its appearance such that it adheres to the rules embodied by a format code. Because the output generated by TEXT is always a text value; numeric, date & time operations cannot be performed on it.
Invocations of the TEXT function take the form:
TEXT(value, format_text)
Example
Consider 2 cells containing the formulae;
="The final day of 2024 is " & TEXT(DATE(2024,12,31),"dddd, mmmm dd.")
="The final day of 2024 is " & DATE(2024,12,31)
Both formulae concatenate the text value “The final day of 2024 is ” with the date December 31st, 2024. The first differs from the second through its use of the TEXT function to both convert the date into a text value and ensure its appearance adheres to a format code.
By contrast the second formula makes no attempt to dictate what the appearance of the date will be once it has been converted to a text value and permits Excel to make that decision. Excel converts the numeric value it uses to represent the date into a text value and embeds that in the result. The result is not what one would expect and illustrates why the TEXT function should always be applied to dates, times & numbers before concatenating them with text values. The diagram below illustrates the differences between the 2 formulae & contrasts their output:
Arguments
Argument | Argument type | Description |
---|---|---|
value | Mandatory | The numeric, date or time value to be converted to a text value. |
format_text | Mandatory | A format code which controls the appearance of TEXT’s output. |
Related Functions
Function | Example | Purpose |
---|---|---|
DOLLAR | DOLLAR(number, decimals) | Transforms a numeric value into a text value and applies currency formatting rules to it. |
VALUETOTEXT | VALUETOTEXT(value, format) | Converts a value of any type to a text value. |
Error Conditions
Error value | Condition type | Condition |
---|---|---|
#VALUE! | Runtime | An attempt was made to apply an inappropriate format code to a value. |
Examples
Example | Formula | Result | Description |
---|---|---|---|
1 | =TEXT(TRUE,) | TRUE | Apply the TEXT function to the logical value TRUE.
|
2 | =TEXT(FALSE,) | TRUE | Apply the TEXT function to the logical value FALSE.
|
3 | =TEXT(DATE(2028,8,14),"Mmm dd yyyy") | Aug 14 2028 | Apply the TEXT function to a date value.
|
4 | =TEXT(1.01,"[Red]0.000") | 1.010 | Apply the TEXT function to a numeric value.
|
Examples: Errors
Example | Formula | Result | Description |
---|---|---|---|
1 | =TEXT(3000000, "dd-mm-yyyy") | #VALUE! | The TEXT function was supplied with a format code applicable to dates, but the value supplied could not be interpreted by Excel as being a dates. |