Skip to main content

TO_DATE

Converts text to a date format

Updated over 2 weeks ago

Description

The TO_DATE() function is used to convert text data into a date format. This is particularly useful when you have text-based date values and need to perform date-related operations on them.

Syntax

TO_DATE(text, [format])

Output

date

Variables

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

  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_DATE(`DOB`)

Name

DOB

TO_DATE(`DOB`)

Giacomo

2/15/1983

1983-02-15

Kameko

4/19/1969

1969-04-19

Anne

2/06/2012

2012-02-06

Orlando

4/28/1988

1988-04-28

Nasim

3/02/2007

2007-03-02

Did this answer your question?