Get the ISO Week Number of a Date in JavaScript

To get the ISO week number, read Temporal.PlainDate.from(date).weekOfYear (with yearOfWeek for the week-based year) — it implements the ISO 8601 rule that trips up hand-written formulas. Part of Date Arithmetic Without Mutations.

Why this scenario is tricky

ISO week numbering has two rules that break naive code: weeks start on Monday, and week 1 is the week containing the year's first Thursday. So 1 January can belong to week 52 or 53 of the previous year, and 31 December can belong to week 1 of the next. weekOfYear and yearOfWeek encode both rules.

Year-boundary weeks are the trap1 Jan can be week 52 of last yearYear-boundary weeks are the trap(dayOfYear/7) formulawrong near year edgesweekOfYear + yearOfWeekISO-correctThe week-based year can differ from the calendar year at both ends.

Minimal working solution

import { Temporal } from '@js-temporal/polyfill';
const d = Temporal.PlainDate.from('2026-01-01');
d.weekOfYear;  // 1  (or 52/53 depending on the year)
d.yearOfWeek;  // the ISO week-based year

Week fieldsweekOfYear and yearOfWeek off a PlainDateWeek fieldsPlainDateweekOfYearyearOfWeek

Full production version

import { Temporal } from '@js-temporal/polyfill';
// Format an ISO week label like '2026-W01'.
function isoWeek(d: Temporal.PlainDate): string {
  return `${d.yearOfWeek}-W${String(d.weekOfYear).padStart(2, '0')}`;
}

ISO week labelCombine week-based year and weekISO week labelPlainDateyearOfWeekweekOfYear'2026-W01'

Verification snippet

ISO Week Number assertionsKey cases assert correctlyAssertions that prove the edge case2026-01-01week 12027-01-01week 53 of 2026first Thursday ruleweek 1label'YYYY-Www'

Common pitfalls

ISO Week Number pitfallsCommon mistakes and their fixesWrongRightdayOfYear / 7ignores Monday startweekOfYear propertyISO ruleuse calendar yearwrong at boundariespair with yearOfWeekcorrect label

Frequently Asked Questions

How do I get the ISO 8601 week number of a date?

Read the weekOfYear property of a Temporal.PlainDate, and pair it with yearOfWeek for the week-based year. These implement the ISO rules — weeks start Monday and week 1 contains the first Thursday — so you never write the fiddly formula yourself.

Why does 1 January sometimes report week 52 or 53?

Under ISO 8601, week 1 is the week containing the year's first Thursday, so early-January days can belong to the last week of the previous week-based year. That is why you use yearOfWeek rather than the calendar year when labelling the week.