Categories:
Conversion Functions

TRY_TO_DATE

A special version of TO_DATE that performs the same operation (i.e. converts an input expression to a date), but with error-handling support (i.e. if the conversion cannot be performed, it returns a NULL value instead of raising an error).

For more information, see Error-handling Conversion Functions.

Syntax

TRY_TO_DATE( <string_expr> )

Arguments

string_expr
The input value should be a string that can be converted to a DATE.

Returns

The data type of the returned value is DATE.

Usage Notes

  • Only works for string expressions.
  • Does not support the optional format argument supported by TO_DATE.

Examples

This demonstrates usage of TRY_TO_DATE:

SELECT TRY_TO_DATE('2018-09-15'), TRY_TO_DATE('Invalid');
+---------------------------+------------------------+
| TRY_TO_DATE('2018-09-15') | TRY_TO_DATE('INVALID') |
|---------------------------+------------------------|
| 2018-09-15                | NULL                   |
+---------------------------+------------------------+