Skip to main content
TO_TEXT

Converts a value, whether it's a datetime or any other data type, to a text format

Updated over a month ago

Description

The TO_TEXT() function is a versatile function used to convert various data types, including datetimes, into text format. This is beneficial when you need to display or manipulate data in text form, such as custom date formatting or converting non-text values to text.

Syntax

TO_TEXT(value), TO_TEXT(datetime, β€œ[format]”)

Variables

  1. value: The value you want to convert to text. This can be a datetime, number, or any other compatible data type.

  2. format: (Optional) A parameter specifying the desired text format for the datetimes or the number. If not provided, a default format is used.

Date Fields

Era

Symbol

Description

G

Replaced with the era string for the current date. One to three letters for the abbreviated form, four letters for the long form, five for the narrow form.

Year

Symbol

Description

y

Replaced by the year. Normally the length specifies the padding, but for two letters it also specifies the maximum length.

Y

Same as y but uses the ISO year-week calendar. ISO year-week increments after completing the last week of the year. Recommend use with the w symbol.

Quarter

Symbol

Description

Q

Use one or two for the numerical quarter, three for the abbreviation, or four for the full name.

q

Use one or two for the numerical quarter, three for the abbreviation, or four for the full name.

Month

Symbol

Description

M

Use one or two for the numerical month, three for the abbreviation, or four for the full name, or five for the narrow name.

L

Use one or two for the numerical month, three for the abbreviation, or four for the full name, or five for the narrow name.

Week

Symbol

Description

w

Week of year according to the ISO year-week calendar. This may have 52 or 53 weeks depending on the year. Recommend use with the Y symbol.

W

Week of month.

Day

Symbol

Description

d

Day of month.

D

Day of year.

F

Day of week in month.

Week Day

Symbol

Description

E

Day of week. Use one through three letters for the short day, or four for the full name, or five for the narrow name.

e

Local day of week. Same as E except adds a numeric value that will depend on the local starting day of the week, using one or two letters.

Time and Timzone Fields

Time Fields

Symbol

Description

a

AM or PM

h

Hour [1-12].

H

Hour [0-23].

K

Hour [0-11].

k

Hour [1-24].

m

Use one or two for zero places padding.

s

Use one or two for zero places padding.

S

Fractional second, rounds to the count of letters.

A

Milliseconds in day.

Timezone Fields

Symbol

Description

z

Use one to three letters for the short timezone or four for the full name.

Z

Use one to three letters for RFC 822, four letters for GMT format.

v

Use one letter for short wall (generic) time, four for long wall time.

V

Same as z, except that timezone abbreviations shoul

Did this answer your question?