Extract the ISO 8601 week number (1 through 53) from a date.
WEEKOFYEAR(date)
## Overview Extracts the ISO 8601 week number from a DATE, returned as an INTEGER between 1 and 53. ISO weeks start on Monday, and the first ISO week of a calendar year is the one that contains the first Thursday of January (equivalently, the week containing January 4). Because ISO weeks do not align with calendar-year boundaries, dates in early January can belong to week 52 or 53 of the previous ISO year, and dates in late December can belong to week 1 of the next ISO year. Always pair WEEKOFYEAR with EXTRACT(ISOYEAR FROM ...) to uniquely identify a week across year boundaries. ## Behavior - Returns an INTEGER in the range 1 through 53. - Returns NULL if the argument is NULL. - Accepts DATE, TIMESTAMP, and TIMESTAMP WITH TIME ZONE inputs. - Weeks start on Monday. - Week 1 is the week containing the first Thursday of the Gregorian calendar year. - Most ISO years have 52 weeks; some have 53. ## Timezone handling - TIMESTAMP WITH TIME ZONE values are converted to the session zone before the week is taken. ## Compatibility - Follows ISO 8601 week-date semantics (week starts Monday, week 1 contains the first Thursday). Widely adopted in analytical SQL engines.
| Name | Type | Description |
|---|---|---|
date | Specifies the date or timestamp from which to extract the ISO week number. |
-- Mid-March returns week 11
SELECT WEEKOFYEAR(DATE '2025-03-15') AS iso_week;
-- Early January can belong to week 1 of the current year or week 52/53 of the previous year
SELECT WEEKOFYEAR(DATE '2025-01-01') AS iso_week_jan1;
-- Late December can belong to week 1 of the next year
SELECT WEEKOFYEAR(DATE '2025-12-29') AS iso_week_dec29;
-- Orders per ISO week
SELECT WEEKOFYEAR(order_date) AS iso_week, COUNT(*) AS orders
FROM commerce.sales.orders
GROUP BY iso_week
ORDER BY iso_week;
-- Combine with ISO year to build a unique week key
SELECT EXTRACT(ISOYEAR FROM order_date) AS iso_year,
WEEKOFYEAR(order_date) AS iso_week,
COUNT(*) AS orders
FROM commerce.sales.orders
GROUP BY iso_year, iso_week
ORDER BY iso_year, iso_week;