Full answer
sql
SELECT strftime('%G-W%V', '2027-01-01') AS iso_week, strftime('%Y-%W', '2027-01-01') AS pct_w,
strftime('%G-W%V', '2027-01-04') AS first_monday;| iso_week | pct_w | first_monday |
|---|---|---|
| 2026-W53 | 2027-00 | 2027-W01 |
%V is the ISO week and %G the ISO year that the week belongs to. 1 January 2027 falls in week 53 of ISO year 2026, so grouping by calendar year plus ISO week would put it in the wrong bucket. Pair %V with %G, never with %Y.
%W counts weeks starting on the first Monday of the calendar year, with earlier days in week 00, which is a different scheme.
PostgreSQL:
sql
SELECT EXTRACT(ISOYEAR FROM DATE '2027-01-01') AS iso_year, EXTRACT(WEEK FROM DATE '2027-01-01') AS iso_week;| iso_year | iso_week |
|---|---|
| 2026 | 53 |
sql
SELECT strftime('%G-W%V', '2027-01-01') AS iso_week, strftime('%Y-%W', '2027-01-01') AS pct_w,
strftime('%G-W%V', '2027-01-04') AS first_monday;Checked on SQLite 3.46.1, run twice with identical output. PostgreSQL results in the answer were checked on PostgreSQL 17.12.
Key points
- ISO weeks start Monday; week 1 contains the first Thursday
- Early January can be in week 52 or 53 of the previous ISO year
- Pair ISO week with ISO year (%G or ISOYEAR)
- %W is not the ISO week
Common mistakes
- Combining calendar year with ISO week
- Using %W and calling it the ISO week
Follow-ups
- How would you group sales by ISO week?
- Which countries use Sunday-start weeks in reporting?
Tips
- Give the 1 January example