Skip to main content

TO_DATETIME

Converts text to a datetime format

Updated this week

Description

The TO_DATETIME() function is used to convert text data into a datetime format. This is useful when you have text-based datetime values and need to work with them in date and time calculations or comparisons.

Syntax

TO_DATETIME(text, [format])

Output

datetime

Variables

  1. text: The text data representing the datetime that you want to convert into a datetime format. It should be in a recognizable datetime format, such as "YYYY-MM-DD HH:MM:SS."

  2. [format]: Optional. Tells TO_DATE() exactly how to interpret the input text. You can often omit this argument when the date is in a common recognizable format and can be auto-parsed correctly.
    ​
    Use [format] when the input could be interpreted more than one way, does not follow a standard format, includes text-based components (ex: month names), or when you want to guarantee consistent parsing. For example, "dd/MM/yyyy" ensures "03/04/2025" is interpreted as 3 April 2025, not March 4, 2025.


    You can build a format pattern using a combination of symbols (ex: yyyy, MM, dd) and literal separators (ex: spaces, commas, slashes, and dashes). The pattern must match the structure of the input text. Supported format symbols are listed below, and symbol capitalization matters. For example, MM represents a month, while mm represents minutes, so using the wrong capitalization can result in incorrect parsing.


    A common mistake is using YYYY (uppercase), which represents a week-based year and can produce unexpected results near year boundaries. Always use lowercase yyyy for calendar year. Additionally, when parsing yy (2-digit year), the year is interpreted relative to a century window. Dates are adjusted to fall within 80 years before and 20 years after the time of calculation. For example, if the calculation runs on 3/25/2026, 3/24/46 is parsed as 3/24/2046 and 3/26/46 is parsed as 3/26/1946.


    Savant format patterns follow standard Unicode (CLDR) and Java date/time conventions.

Symbol

Meaning

Example

yyyy

Year (4 digit)

2025

yy

Year (2 digit)

25

MM

Month number

03

MMM

Month short

Mar

MMMM

Month full

March

dd

Day of month

15

EEE

Weekday short

Sat

EEEE

Weekday full

Saturday

HH

Hour (24h)

14

hh

Hour (12h)

02

mm

Minute

30

ss

Second

45

a

AM/PM

PM

Q

Quarter

1

Example

TO_DATETIME(CONCAT(TO_DATE(Registration Date`)," ",Registration Time`))

Name

Registration Date

Registration Time

TO_DATETIME

Giacomo

April 22, 2024

20:21:42

2024-04-22T16:21:42000-04:00

Kameko

May 22, 2024

11:30:38

2024-05-22T07:30:38000-04:00

Anne

May 3, 2024

13:11:30

2024-05-03T09:11:30000-04:00

Orlando

July 25, 2024

2:29:42

2024-07-24T22:29:42000-04:00

Nasim

December 11, 2023

13:29:58

2023-12-11T08:29:58000-05:00

Did this answer your question?