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 2 weeks 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 and Time Formatting

When formatting datetimes, Savant uses pattern strings where letters represent parts of the date/time and other characters are treated as literal text.

Quick reference patterns

What you want

Pattern

Example output

Standard date

yyyy-MM-dd

2025-03-15

Standard datetime

yyyy-MM-dd HH:mm:ss

2025-03-15 14:30:00

US date style

MM/dd/yyyy

03/15/2025

European date style

dd/MM/yyyy

15/03/2025

Month and year only

yyyy-MM

2025-03

Readable date

MMMM d, yyyy

March 15, 2025

Readable with weekday

EEEE, MMMM d, yyyy

Saturday, March 15, 2025

Common Tokens

Category

Tokens

Meaning

Date

yyyy, yy

Year (4-digit, 2-digit)

Date

M, MM, MMM, MMMM

Month (1–2 digit number, 2-digit number, short name, full name)

Date

d, dd

Day of month (1–2 digit number, 2-digit number)

Date

EEE, EEEE

Weekday (short name, full name)

Date

Q

Quarter

Time

H, HH

Hour, 24-hour clock (0–23, 2-digit)

Time

h, hh

Hour, 12-hour clock (1–12, 2-digit)

Time

m, mm

Minute (1–2 digit number, 2-digit number)

Time

s, ss

Second (1–2 digit number, 2-digit number)

Time

a

AM/PM marker

Literal Text

Non-pattern characters (dashes, slashes, colons, spaces) appear as written. If you need to include text that could be mistaken for pattern letters, wrap it in single quotes (ex: 'T', 'at').

Examples

Use Case

Formula

Example Output

Basic conversion (no format)

TO_TEXT([Order ID])

"12345"

Date only

TO_TEXT([Created At], "yyyy-MM-dd")

2025-03-15

Datetime (24-hour)

TO_TEXT([Created At], "yyyy-MM-dd HH:mm:ss")

2025-03-15 14:30:00

Readable datetime (12-hour)

TO_TEXT([Created At], "MMM d, yyyy h:mm a")

Mar 15, 2025 2:30 PM

Timestamp for filenames

TO_TEXT([Created At], "yyyyMMdd_HHmmss")

20250315_143052

Gotchas

Case sensitivity matters

Uppercase and lowercase letters mean different things – mixing them up is a common source of bugs.

  • Use yyyy for calendar year – avoid YYYY unless you specifically need week-based year behavior.

  • Use dd for day of month – avoid DD unless you specifically need day of year.

  • MM is month, mm is minute.

12-hour vs 24-hour time

  • Prefer HH (24-hour) for data processing

  • Use hh with a for user-facing displays

Did this answer your question?