TO_TIME

functionsupportedCore SQL functions

docs.snowflake.com ↗

Conversion functionsDate & time functions

Converts an input expression into a time.

Syntax

supportedpartialnot supportednot scored

TO_TIME( <string_expr> [, <format> ] )
TO_TIME( <timestamp_expr> )
TO_TIME( '<integer>' )
TO_TIME( <variant_expr> )

TIME( <string_expr> )
TIME( <timestamp_expr> )
TIME( '<integer>' )
TIME( <variant_expr> )

Parameters

NameRequiredDescription
string_expr or timestamp_expr or 'integer' or variant_exprrequiredExpression to be converted into a time: For string_expr, the string to convert to a time. For timestamp_expr, the timestamp to convert to a time. The function returns the time portion of the input value. For 'integer', a string containing an integer to convert to a time. The integer is treated as a number of seconds, milliseconds, microseconds, or nanoseconds after the start of the Unix epoch. See the Usage Notes. For this timestamp, the function gets the number of seconds after the start of the Unix epoch. The function performs a modulo operation to get the remainder from dividing this number by the number of seconds in a day (86400): number_of_seconds % 86400 The function interprets this remainder as the number of seconds after midnight. For example, suppose that the value is '31536002789'. Based on the magnitude of this value, the function uses milliseconds as the unit of time and determines that the value represents 1971-01-01 00:00:02.789. The function gets the number of seconds after the Unix epoch for this value (31536002). The function gets the remainder from dividing that number by the number of seconds in a day (31536002 % 86400). The function uses the remainder (2) as the number of seconds after midnight. The resulting time is 00:00:02. For variant_expr: If the VARIANT contains a string in TIME format (such as HH:MI:SS), a string conversion is performed. If the VARIANT contains a string in INTEGER format, a string conversion is performed and the value is treated as the number of seconds since midnight (modulus 86400 if necessary). If the VARIANT contains a JSON null value, the output is NULL. For all other values, a conversion error is generated.
formatoptionalTime format specifier for string_expr or AUTO, which specifies that Snowflake automatically detects the format to use. For more information, see Date and time formats in conversion functions. Default: The current value of the TIME_INPUT_FORMAT session parameter (default AUTO)

Returns

The data type of the returned value is TIME. If the input is NULL, returns NULL.

Usage notes

See also