Outdated Version

You are viewing an older version of this section. View current production version.

TO_DATE

Converts a string to a DATE value.

Syntax

TO_DATE ( convert_from_value, convert_from_format )

Arguments

convert_from_value

A string specifying the value to convert from.

convert_from_format

A format string, comprised of one or more format specifiers.

Info

convert_from_format may contain characters that are not format specifiers. These characters must appear in the same position in convert_from_value; otherwise, TO_DATE will return NULL.

Examples

The following example demonstrates a typical call to TO_DATE, where the string to be converted is specified in MM/DD/YYYY format.

SELECT TO_DATE('03/01/2018','MM/DD/YYYY') AS result;

Output:

+------------+
| result     |
+------------+
| 2018-03-01 |
+------------+

The following example demonstrates another call to TO_DATE, where the string to be converted contains the spelling of the month. In this example, the string The day is is included in the same location in both arguments, allowing the function to successfully return a DATE value.

SELECT TO_DATE('The day is March 01, 2018','The day is MONTH DD, YYYY') AS result;

Output:

+------------+
| result     |
+------------+
| 2018-03-01 |
+------------+