Skip to content

Latest commit

 

History

History
38 lines (28 loc) · 1.05 KB

File metadata and controls

38 lines (28 loc) · 1.05 KB
description
Extracts the year for a given date or timestamp.

YEAR

Syntax

EXTRACT(YEAR FROM date_timestamp_expression string) → bigint

  • date_timestamp_expression: A DATE or TIMESTAMP expression.

Examples

{% code title="YEAR example using a timestamp." %}

SELECT EXTRACT(YEAR FROM TIMESTAMP '2019-08-12 01:00:00.123456')
-- 2019

{% endcode %}

{% code title="YEAR example using a date." %}

SELECT EXTRACT(YEAR FROM DATE '2019-08-12')
-- 2019

{% endcode %}

{% code title="YEAR example using the CAST function." %}

SELECT EXTRACT(YEAR FROM CAST('2019-08-12 01:00:00' AS TIMESTAMP))
-- 2019

{% endcode %}

Usage Notes

This function uses the EXTRACT function. When using the CAST function, timestamps containing milliseconds are not allowed.