Categories:

Semi-structured and structured data functions (Type Predicates)

IS_TIMESTAMP_*¶

Verifies whether a VARIANT argument contains the respective timestamp value:

  • IS_TIMESTAMP_LTZ (value with local time zone).

  • IS_TIMESTAMP_NTZ (value with no time zone).

  • IS_TIMESTAMP_TZ (value with time zone).

See also:

IS_<object_type> , IS_DATE , IS_DATE_VALUE , IS_TIME

Syntax¶

IS_TIMESTAMP_LTZ( <variant_expr> )

IS_TIMESTAMP_NTZ( <variant_expr> )

IS_TIMESTAMP_TZ( <variant_expr> )
Copy

Arguments¶

variant_expr

An expression that evaluates to a value of type VARIANT.

Returns¶

Returns a BOOLEAN value or NULL.

  • Returns TRUE if the VARIANT value contains a timestamp. Otherwise, returns FALSE.

  • If the input is NULL, returns NULL without reporting an error.

Examples¶

Show all timestamps in a VARIANT column, with the output using the time zone specified for the session.

Note

The output format for the time zone is set using a parameter:

In these examples, the local time zone is US Pacific Standard Time (-08:00 relative to GMT/UCT).

Create and load a table with various date and time values in a VARIANT column:

CREATE OR REPLACE TABLE vardttm (v VARIANT);
Copy
INSERT INTO vardttm SELECT TO_VARIANT(TO_DATE('2024-02-24'));
INSERT INTO vardttm SELECT TO_VARIANT(TO_TIME('20:57:01.123456789+07:00'));
INSERT INTO vardttm SELECT TO_VARIANT(TO_TIMESTAMP('2023-02-24 12:00:00.456'));
INSERT INTO vardttm SELECT TO_VARIANT(TO_TIMESTAMP_LTZ('2022-02-24 13:00:00.123 +01:00'));
INSERT INTO vardttm SELECT TO_VARIANT(TO_TIMESTAMP_NTZ('2021-02-24 14:00:00.123 +01:00'));
INSERT INTO vardttm SELECT TO_VARIANT(TO_TIMESTAMP_TZ('2020-02-24 15:00:00.123 +01:00'));
Copy

Use the TYPEOF function in a query to show the data types of the values stored in the VARIANT column v:

SELECT v, TYPEOF(v) AS type FROM vardttm;
Copy
+---------------------------------+---------------+
| V                               | TYPE          |
|---------------------------------+---------------|
| "2024-02-24"                    | DATE          |
| "20:57:01"                      | TIME          |
| "2023-02-24 12:00:00.456"       | TIMESTAMP_NTZ |
| "2022-02-24 04:00:00.123 -0800" | TIMESTAMP_LTZ |
| "2021-02-24 14:00:00.123"       | TIMESTAMP_NTZ |
| "2020-02-24 15:00:00.123 +0100" | TIMESTAMP_TZ  |
+---------------------------------+---------------+

Show the TIMESTAMP_NTZ values in the data by using the IS_TIMESTAMP_NTZ function in a WHERE clause:

SELECT * FROM vardttm WHERE IS_TIMESTAMP_NTZ(v);
Copy
+---------------------------+
| V                         |
|---------------------------|
| "2023-02-24 12:00:00.456" |
| "2021-02-24 14:00:00.123" |
+---------------------------+

Show the TIMESTAMP_LTZ values in the data by using the IS_TIMESTAMP_LTZ function in a WHERE clause:

SELECT * FROM vardttm WHERE IS_TIMESTAMP_LTZ(v);
Copy
+---------------------------------+
| V                               |
|---------------------------------|
| "2022-02-24 04:00:00.123 -0800" |
+---------------------------------+

Show the TIMESTAMP_TZ values in the data by using the IS_TIMESTAMP_TZ function in a WHERE clause:

SELECT * FROM vardttm WHERE IS_TIMESTAMP_TZ(v);
Copy
+---------------------------------+
| V                               |
|---------------------------------|
| "2020-02-24 15:00:00.123 +0100" |
+---------------------------------+