Categories:

Conversion Functions

TRY_TO_TIME

A special version of TO_TIME that performs the same operation (i.e. converts an input expression into a time), 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_TIME( <string_expr> )

Arguments

string_expr

This should be a string that can be converted to a valid time.

Returns

The data type of the returned value is TIME.

Usage Notes

  • Only works for string expressions.

  • Does not support the optional format argument supported by TO_TIME.

Examples

This demonstrates usage of TRY_TO_TIME:

SELECT TRY_TO_TIME('12:30:00'), TRY_TO_TIME('Invalid');
+-------------------------+------------------------+
| TRY_TO_TIME('12:30:00') | TRY_TO_TIME('INVALID') |
|-------------------------+------------------------|
| 12:30:00                | NULL                   |
+-------------------------+------------------------+