Skip to content
SQLSimplified
conversion

TO_DATE()

Parses a string into a DATE using a format pattern.

Description

TO_DATE converts a text value into a real DATE by interpreting it according to a format pattern. It's essential when your dates arrive as strings (from a file or API) and you need to do date math or comparisons on them.

Syntax

TO_DATE('2023-01-15', 'YYYY-MM-DD')

Parameters

NameDescriptionOptional
stringThe text to parse.No
formatThe pattern matching the input layout.No

Return Type

Returns a DATE.

Examples

Employees & Departments

Loading database engine...

Employees & Departments

Loading database engine...

TO_DATE vs CAST

CAST('2023-01-15' AS DATE) works for ISO formats; TO_DATE handles arbitrary layouts via a pattern.

Common Mistakes

  • Pattern mismatch. If the format doesn't match the string, parsing fails or returns wrong values — align them exactly.
  • Format dialect. Pattern tokens vary by engine; check your database's docs.
  • Time-of-day input. TO_DATE drops any time component; use TO_TIMESTAMP if you need it.

See also: TO_CHAR, CAST, DATE_TRUNC.

Search

Search lessons, functions, examples, and practice problems