EXTRACT
Retrieves subfields such as year or hour from date/time values.
Syntax
EXTRACT(<field> FROM <source>)
Parameter | Description |
---|---|
<field> | Supported fields: DAY , DOW, MONTH , WEEK , WEEKISO , QUARTER , YEAR , HOUR , MINUTE , SECOND , EPOCH |
<source> | A value expression of type timestamp. |
Example
This example below extracts the year from the timestamp. The string date first need to be transformed to TIMESTAMP
type using the CAST
function.
SELECT
EXTRACT(
YEAR
FROM
CAST('2020-01-01 10:00:00' AS TIMESTAMP)
);
Returns: 2020