TO_DATE

functionsupportedCore SQL functions

docs.snowflake.com ↗

Conversion functionsDate & time functions

Converts an input expression to a date: - For a VARCHAR expression, the result of converting the string to a date. - For a TIMESTAMP expression, the date from the timestamp. - For a VARIANT expression: If the VARIANT contains a string, a string conversion is performed. - If the VARIANT contains a date, the date value is preserved as is. - If the VARIANT contains a JSON null value, the output is NULL. - For NULL input, the output is NULL. For all other values, a conversion error is generated.

Syntax

supportedpartialnot supportednot scored

TO_DATE( <string_expr> [, <format> ] )
TO_DATE( <timestamp_expr> )
TO_DATE( '<integer>' )
TO_DATE( <variant_expr> )

DATE( <string_expr> [, <format> ] )
DATE( <timestamp_expr> )
DATE( '<integer>' )
DATE( <variant_expr> )

Parameters

NameRequiredDescription
string_exprrequiredString from which to extract a date. For example: '2024-01-31'.
timestamp_exprrequiredA TIMESTAMP expression. The DATE portion of the TIMESTAMP value is extracted.
'integer'requiredAn expression that evaluates to a string containing an integer. For example: '15000000'. Depending on the magnitude of the string, it can be interpreted as seconds, milliseconds, microseconds, or nanoseconds. For details, see the Usage notes for this function.
variant_exprrequiredAn expression of type VARIANT. The VARIANT must contain one of the following: A string from which to extract a date. A date. A string containing an integer that represents the number of seconds or milliseconds. Although TO_DATE accepts a TIMESTAMP value, it does not accept a TIMESTAMP value inside a VARIANT.
formatoptionalDate format specifier for string_expr or AUTO, which specifies that Snowflake automatically detects the format to use. For more information, see Date and time formats in conversion functions. The default is the current value of the DATE_INPUT_FORMAT session parameter (default AUTO).

Returns

The data type of the returned value is DATE. If the input is NULL, returns NULL.

Usage notes

See also