Data Types and Functions in Snowflake
Jake Roach
Field Data Engineer
2023-04-01
YYYY-MM-DD
CREATE TABLE sales (
transaction_date DATE -- Define a column of type `DATE`
);
SELECT
TO_DATE('2023-04-01') AS the_date, -- Convert a string into a DATE
'2023-04-01'::DATE AS casted_date -- Casted using <value>::DATE
;
the_date | casted_date
----------- | ------------
2023-04-01 | 2023-04-01
08:24:08
HH:MM:SS
CREATE TABLE sales (
transaction_time TIME -- Create a column with the `TIME` keyword
);
TIME
columnSELECT
TO_TIME('08:24:04') AS the_time,
'08:24:04'::TIME AS casted_time
;
| the_time | casted_time |
| ---------- | ----------- |
| 08:24:08 | 08:24:08 |
TO_TIME
function::
TIMESTAMP
captures both date and time 2023-04-01 08:24:04
YYYY-MM-DD HH:MM:SS
CREATE TABLE (
transaction_timestamp TIMESTAMP
);
SELECT
TO_TIMESTAMP('2023-04-01 08:24:04') AS the_timestamp,
'2023-04-01 08:24:04'::TIMESTAMP AS casted_timestamp
;
TO_TIMESTAMP
or <value>::TIMESTAMP
the_timestamp | casted_timestamp
--------------------- | ----------------------
2024-04-01 08:24:08 | 2024-04-01 08:24:08
SELECT TO_DATE('2021-05-14') AS the_date, TO_TIME('06:13:00') AS the_time, TO_TIMESTAMP('2021-05-14T06:13:00') AS the_timestamp,
-- Extract the DATE from a TIMESTAMP, we could do the same with TIME! transaction_timestamp::DATE AS casted_date
;
the_date | the_time | the_timestamp | casted_date
------------ | ----------- | -------------------- | ------------
2021-05-14 | 06:13:00 | 2021-05-14T06:13:00 | 2021-05-14
By default, DATE
, TIME
, and TIMESTAMP
's are stored without a timezone
$$
TIMESTAMP_NTZ
TIMESTAMP
$$
TIMESTAMP_LTZ
$$
TIMESTAMP_TZ
Data Types and Functions in Snowflake