ISO 8601 assigns a date to the week that contains its Thursday, and the ISO week number is the count of Thursdays from the start of the ISO year. This single rule, called the first-Thursday rule, determines every week number deterministically.
The first-Thursday rule
The rule states that week 1 of an ISO year is the week containing the first Thursday of January. Equivalently, week 1 contains 4 January. Weeks always run Monday to Sunday.
Thursday is the pivot for a precise reason. A week has seven days, and the year cuts the week at some point. Thursday is the only weekday that guarantees the week has at least four days in the new calendar year, no matter which weekday 1 January lands on. This four-day majority defines the ISO week-based year.
The standard is published as ISO 8601-1:2019 by the International Organization for Standardization (see https://www.iso.org/iso-8601-date-and-time-format.html).
Step-by-step algorithm
The algorithm has five steps. It works for any date.
- Find the Thursday of the same week as the input date. Monday to Thursday is plus 3 days. Tuesday to Thursday is plus 2. Wednesday is plus 1. Thursday is zero. Friday is minus 1. Saturday is minus 2. Sunday is minus 3.
- The ISO year is the calendar year of that Thursday.
- Find 4 January of that ISO year. This date is always in ISO week 1.
- Find the Thursday of the week containing 4 January. Call this the reference Thursday.
- The ISO week number is
((target Thursday − reference Thursday) / 7) + 1.
Every output is an integer between 1 and 53. No date escapes this method.
Worked examples
Three examples cover the common cases: a midyear date, a year-boundary date, and a 53-week year.
28 May 2026 (Thursday) gives ISO 2026-W22.
- The input is a Thursday, so the target Thursday is 28 May 2026.
- ISO year is 2026.
- 4 January 2026 is a Sunday, so the reference Thursday is 1 January 2026.
- Day difference: 28 May minus 1 January is 147 days.
- Week number: 147 / 7 = 21; plus 1 equals 22.
1 January 2023 (Sunday) gives ISO 2022-W52.
- Sunday shifts back 3 days, so the target Thursday is 29 December 2022.
- ISO year is 2022.
- 4 January 2022 is a Tuesday, so the reference Thursday is 6 January 2022.
- Day difference: 29 December 2022 minus 6 January 2022 is 357 days.
- Week number: 357 / 7 = 51; plus 1 equals 52.
31 December 2026 (Thursday) gives ISO 2026-W53.
- The input is a Thursday, so the target Thursday is 31 December 2026.
- ISO year is 2026.
- The reference Thursday is 1 January 2026 (same as the first example).
- Day difference: 31 December minus 1 January is 364 days.
- Week number: 364 / 7 = 52; plus 1 equals 53. The year 2026 is a 53-week year.
Formulas and code
Every major language and database includes a built-in ISO function. Use the built-in rather than hand-rolling the algorithm.
Python returns the ISO triple from a single method call.
from datetime import date
iso_year, iso_week, iso_weekday = date(2026, 5, 28).isocalendar()
# (2026, 22, 4)
JavaScript exposes ISO week and ISO year through the Temporal API.
Temporal.PlainDate.from("2026-05-28").weekOfYear; // 22
Temporal.PlainDate.from("2026-05-28").yearOfWeek; // 2026
Microsoft Excel offers two equivalent formulas.
=ISOWEEKNUM(DATE(2026, 5, 28)) // 22
=WEEKNUM(DATE(2026, 5, 28), 21) // 22 (mode 21 = ISO)
PostgreSQL exposes both the week and the ISO year via EXTRACT.
SELECT EXTRACT(week FROM DATE '2026-05-28'); -- 22
SELECT EXTRACT(isoyear FROM DATE '2026-05-28'); -- 2026
Common mistakes
Three errors cause the bulk of ISO week bugs in production code and spreadsheets.
- Confusing the ISO year with the calendar year for dates in late December or early January. The ISO year of 1 January 2023 is 2022, not 2023.
- Using Excel's default
=WEEKNUM(date)when ISO is required. The default uses Sunday-start weeks and produces different numbers from=ISOWEEKNUM(date). - Forgetting that some years have 53 weeks. A year-end report that assumes 52 weeks loses a week of data in 2026, 2032, and 2037.
Related articles
FAQ
What's the simplest way to calculate ISO week numbers in Excel?
Use =ISOWEEKNUM(date) in Excel 2013 or later. The formula =WEEKNUM(date, 21) returns the same value and works in older versions that support mode arguments.
Why does my date fall in a different year under ISO? Late December and early January dates inherit their ISO year from the week's Thursday. If the Thursday sits in the prior or following calendar year, the ISO year shifts with it.
How do I tell if a year has 53 weeks? A year has 53 weeks when 1 January is a Thursday, or when 1 January is a Wednesday in a leap year. The next 53-week years are 2026, 2032, 2037, 2043, and 2048.