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.
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
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')}`;
}
Verification snippet
Common pitfalls
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.