Categories: Date/Time
YEAR
Extracts the year for a given date or timestamp.
Syntax
EXTRACT(YEAR FROM date_timestamp_expression string) → bigint
- date_timestamp_expression: A
DATE
orTIMESTAMP
expression.
Examples
YEAR example using a timestampSELECT EXTRACT(YEAR FROM TIMESTAMP '2019-08-12 01:00:00.123456')
-- 2019
SELECT EXTRACT(YEAR FROM DATE '2019-08-12')
-- 2019
SELECT EXTRACT(YEAR FROM CAST('2019-08-12 01:00:00' AS TIMESTAMP))
-- 2019
Usage Notes
This function uses the EXTRACT
function. When using the CAST
function, timestamps containing milliseconds are not allowed.