A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.snowflake.com/en/sql-reference/functions/to_time below:

Website Navigation


TO_TIME , TIME | Snowflake Documentation

Categories:

Conversion functions , Date & time functions

TO_TIME , TIME

Converts an input expression into a time.

See also:

TRY_TO_TIME

Syntax
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> )

Copy

Arguments

Required:

string_expr or timestamp_expr or 'integer' or variant_expr

Expression to be converted into a time:

For all other values, a conversion error is generated.

Optional:

format

Time 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
Examples

These examples use the TO_TIME and TIME functions.

SELECT TO_TIME('13:30:00'), TIME('13:30:00');

Copy

+---------------------+------------------+
| TO_TIME('13:30:00') | TIME('13:30:00') |
|---------------------+------------------|
| 13:30:00            | 13:30:00         |
+---------------------+------------------+
SELECT TO_TIME('13:30:00.000'), TIME('13:30:00.000');

Copy

+-------------------------+----------------------+
| TO_TIME('13:30:00.000') | TIME('13:30:00.000') |
|-------------------------+----------------------|
| 13:30:00                | 13:30:00             |
+-------------------------+----------------------+

This example shows how to use the TO_TIME function to process field separators other than the default colons. The example uses the period character as the separator between hours and minutes, and between minutes and seconds:

SELECT TO_TIME('11.15.00', 'HH24.MI.SS');

Copy

+-----------------------------------+
| TO_TIME('11.15.00', 'HH24.MI.SS') |
|-----------------------------------|
| 11:15:00                          |
+-----------------------------------+

This example demonstrates how the TO_TIME function interprets a string containing an integer:

CREATE OR REPLACE TABLE demo1_time (
  description VARCHAR,
  value VARCHAR -- string rather than bigint
);

INSERT INTO demo1_time (description, value) VALUES
  ('Seconds',      '31536001'),
  ('Milliseconds', '31536002400'),
  ('Microseconds', '31536003600000'),
  ('Nanoseconds',  '31536004900000000');

Copy

SELECT description,
       value,
       TO_TIMESTAMP(value),
       TO_TIME(value)
  FROM demo1_time
  ORDER BY value;

Copy

+--------------+-------------------+-------------------------+----------------+
| DESCRIPTION  | VALUE             | TO_TIMESTAMP(VALUE)     | TO_TIME(VALUE) |
|--------------+-------------------+-------------------------+----------------|
| Seconds      | 31536001          | 1971-01-01 00:00:01.000 | 00:00:01       |
| Milliseconds | 31536002400       | 1971-01-01 00:00:02.400 | 00:00:02       |
| Microseconds | 31536003600000    | 1971-01-01 00:00:03.600 | 00:00:03       |
| Nanoseconds  | 31536004900000000 | 1971-01-01 00:00:04.900 | 00:00:04       |
+--------------+-------------------+-------------------------+----------------+

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4