Extract the four-digit year component from a date or timestamp.
YEAR(date)
## Overview Extracts the year component from a DATE or TIMESTAMP, returned as a four-digit INTEGER. Equivalent to EXTRACT(YEAR FROM input). Use YEAR for simple year-based filtering, GROUP BY aggregation, or as a building block for year-month bucketing. For non-Gregorian calendars or ISO-year semantics (weeks that belong to the previous or next ISO year) use EXTRACT or WEEKOFYEAR helpers. ## Behavior - Returns an INTEGER. - Returns NULL if the argument is NULL. - Accepts DATE, TIMESTAMP, and TIMESTAMP WITH TIME ZONE inputs. - For TIMESTAMP WITH TIME ZONE, the year corresponds to the calendar year in the session time zone. - Returns the Gregorian calendar year (proleptic for dates before 1583). ## Timezone handling - For TIMESTAMP WITHOUT TIME ZONE, the stored wall-clock year is returned. - For TIMESTAMP WITH TIME ZONE, the instant is converted to the session zone first; two sessions in different zones can see different years for an instant near midnight on New Year's Eve. ## Compatibility - Equivalent to the SQL standard EXTRACT(YEAR FROM source). The bare YEAR(x) form is a widely supported shorthand.
| Name | Type | Description |
|---|---|---|
date | Specifies the date or timestamp from which to extract the year. TIMESTAMP values are converted to DATE in the session time zone. |
-- Extract the year from a literal
SELECT YEAR(DATE '2025-07-04') AS year;
-- Current calendar year
SELECT YEAR(CURRENT_DATE()) AS current_year;
-- Group revenue by order year
SELECT YEAR(order_date) AS order_year, SUM(total_amount) AS revenue
FROM commerce.sales.orders
GROUP BY order_year
ORDER BY order_year;
-- Filter rows to a specific year
SELECT event_id, event_ts
FROM analytics.events.user_activity
WHERE YEAR(event_ts) = 2025;
-- Combined year + month bucketing via concatenation
SELECT YEAR(order_date) * 100 + MONTH(order_date) AS yyyymm, COUNT(*) AS orders
FROM commerce.sales.orders
GROUP BY yyyymm
ORDER BY yyyymm;