Computes the ISO 8601 week-numbering year and week number for a given date.
Published for review. The Founder is checking every card himself; anything he strikes comes down the same hour.
Try it
Inputs
date (string, required) : ISO 8601 date, YYYY-MM-DD
Outputs
iso_year: ISO week-numbering year (may differ from the calendar year near year boundaries)
iso_week (week): ISO week number, 1 to 53
Steps
Parse the date as a proleptic Gregorian civil date and find its ISO weekday (Monday=1 .. Sunday=7) from the day-number modulo 7 (Hinnant days_from_civil, cited above), calibrated against 1970-01-01 being a Thursday.
Find the Thursday of the same ISO week: subtract (iso_weekday - 4) days from the date's day-number.
The ISO week-numbering year is the calendar year that Thursday falls in.
iso_week = floor((Thursday's day-number - day-number of January 1 of the ISO week-numbering year) / 7) + 1.
Constants
None.
Sources
Data elements and interchange formats -- Information interchange -- Representation of dates and times (International Organization for Standardization, 2026-09-30T19:41:35Z) - defines the week-date system: weeks run Monday to Sunday, week 1 contains the year's first Thursday