- Categories:
TRY_TO_TIME¶
A special version ofTO_TIME , TIME that performs the same operation (i.e.converts an input expression into a time), but with error-handlingsupport (i.e. if the conversion cannot be performed, it returns a NULL valueinstead of raising an error).
For more information, seeError-handling conversion functions.
- See also:
Syntax¶
TRY_TO_TIME(<string_expr>[,<format>])TRY_TO_TIME('<integer>')
Arguments¶
Required:
One of:
string_exprA string that can be converted to a valid time.
'integer'An expression that evaluates to a string containing an integer, for example
'15000000'. Dependingon the magnitude of the string, it can be interpreted as seconds, milliseconds, microseconds, ornanoseconds. For details, see theUsage Notes.
Optional:
formatFormat specifier for
string_exprorAUTO.For more information, seeDate and time formats in conversion functions.The default is the current value of theTIME_INPUT_FORMATsession parameter (default AUTO).
Returns¶
The data type of the returned value is TIME.
Usage notes¶
The display format for times in the output is determined by theTIME_OUTPUT_FORMATsession parameter (default
HH24:MI:SS).If the format of the input parameter is a string that contains an integer, the unit of measurement for the value (seconds,microseconds, milliseconds, or nanoseconds) is determined as follows:
After the string is converted to an integer, the integer is treated as a number of seconds, milliseconds,microseconds, or nanoseconds after the start of the Unix epoch (1970-01-01 00:00:00.000000000 UTC).
If the integer is less than 31536000000 (the number of milliseconds in a year), then the value is treated asa number of seconds.
If the value is greater than or equal to 31536000000 and less than 31536000000000, then the value is treatedas milliseconds.
If the value is greater than or equal to 31536000000000 and less than 31536000000000000, then the value istreated as microseconds.
If the value is greater than or equal to 31536000000000000, then the value istreated as nanoseconds.
If more than one row is evaluated (for example, if the input is the column name of a table that contains more thanone row), each value is examined independently to determine if the value represents seconds, milliseconds, microseconds, ornanoseconds.
Examples¶
This example uses TRY_TO_TIME:
SELECTTRY_TO_TIME('12:30:00'),TRY_TO_TIME('Invalid');
+-------------------------+------------------------+| TRY_TO_TIME('12:30:00') | TRY_TO_TIME('INVALID') ||-------------------------+------------------------|| 12:30:00 | NULL |+-------------------------+------------------------+
SeeTO_TIME , TIME for examples that convert an input expression to a time.