TO_DATE - Amazon Redshift

TO_DATE

TO_DATE converts a date represented in a character string to a DATE data type.

The second argument is a format string that indicates how the character string should be parsed to create the date value.

Syntax

TO_DATE (string, format)

Arguments

string

String to be converted.

format

A string literal that defines the format of the input string, in terms of its date parts. For a list of valid formats, see Datetime format strings.

Return type

TO_DATE returns a DATE, depending on the format value.

If the conversion to format fails, then an error is returned.

Example

The following command converts the date 02 Oct 2001 into the default date format:

select to_date ('02 Oct 2001', 'DD Mon YYYY'); to_date ------------ 2001-10-02 (1 row)