Why ISO 8601 instead of another system?
ISO 8601 is the international standard for week numbering. It defines unambiguously when a week starts (Monday) and how week 1 is counted.
See what week of the year it is right now in Canada, including the current week number and the dates this week starts and ends.
15 languages, copy-paste ready. Compute the ISO 8601 week number and ISO week-year in JavaScript, Python, SQL, Excel, and more.
Pure ECMAScript, no dependencies. Returns 1–53.
function isoWeek(date) {
const d = new Date(Date.UTC(
date.getFullYear(),
date.getMonth(),
date.getDate(),
));
// Thursday in current week decides the year.
d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
return Math.ceil(((d - yearStart) / 86400000 + 1) / 7);
}
console.log(isoWeek(new Date())); // current ISO week numberReturns both the ISO week number and the ISO week-year.
// Intl.DateTimeFormat doesn't expose ISO weeks; use the formula above.
export function isoWeek(date: Date): number {
const d = new Date(Date.UTC(
date.getFullYear(),
date.getMonth(),
date.getDate(),
));
d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
return Math.ceil(((d.getTime() - yearStart.getTime()) / 86_400_000 + 1) / 7);
}
export function isoWeekYear(date: Date): number {
const d = new Date(Date.UTC(
date.getFullYear(),
date.getMonth(),
date.getDate(),
));
d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
return d.getUTCFullYear();
}isocalendar() returns ISO 8601 (year, week, weekday) since Python 3.9.
from datetime import date
# Python 3.9+: date.isocalendar() returns a named tuple
year, week, weekday = date.today().isocalendar()
print(f"{year}-W{week:02d}-{weekday}")DateTime::format with `o` (ISO year) and `W` (ISO week).
<?php
$today = new DateTime("now", new DateTimeZone("America/Toronto"));
echo $today->format("o-\WW"); // ISO week-year + ISO week, e.g. 2026-W18java.time.WeekFields.ISO is the standards-compliant accessor.
import java.time.LocalDate;
import java.time.temporal.WeekFields;
LocalDate today = LocalDate.now();
int week = today.get(WeekFields.ISO.weekOfWeekBasedYear());
int year = today.get(WeekFields.ISO.weekBasedYear());
System.out.printf("%d-W%02d%n", year, week);System.Globalization.ISOWeek (.NET Core 3.0+).
using System.Globalization;
var today = DateTime.UtcNow;
int week = ISOWeek.GetWeekOfYear(today);
int year = ISOWeek.GetYear(today);
Console.WriteLine($"{year}-W{week:D2}");time.Time.ISOWeek returns (year, week) in ISO 8601.
package main
import (
"fmt"
"time"
)
func main() {
year, week := time.Now().UTC().ISOWeek()
fmt.Printf("%d-W%02d\n", year, week)
}chrono::NaiveDate::iso_week returns the ISO week.
use chrono::{Datelike, Utc};
fn main() {
let now = Utc::now().date_naive();
let iso = now.iso_week();
println!("{}-W{:02}", iso.year(), iso.week());
}Date#cweek (calendar week) and Date#cwyear (calendar week year).
require "date"
puts Date.today.cweek # ISO 8601 week number
puts Date.today.cwyear # ISO 8601 week-yearPostgres EXTRACT WEEK is ISO 8601 by default.
SELECT
EXTRACT(ISOYEAR FROM CURRENT_DATE) AS iso_year,
EXTRACT(WEEK FROM CURRENT_DATE) AS iso_week;Mode 3 forces ISO 8601 (week 1 = first week with 4+ days).
SELECT
YEARWEEK(CURRENT_DATE, 3) AS iso_year_week, -- mode 3 = ISO 8601
WEEK(CURRENT_DATE, 3) AS iso_week;DATEPART(ISO_WEEK, ...) was added in SQL Server 2008.
SELECT
DATEPART(ISO_WEEK, GETUTCDATE()) AS iso_week,
DATEPART(YEAR, DATEADD(DAY, 26 - DATEPART(ISO_WEEK, GETUTCDATE()), GETUTCDATE())) AS iso_year;Standard SQL ISOWEEK / ISOYEAR.
SELECT
EXTRACT(ISOWEEK FROM CURRENT_DATE()) AS iso_week,
EXTRACT(ISOYEAR FROM CURRENT_DATE()) AS iso_year;Excel 2013+ has ISOWEEKNUM. Older versions need a manual formula.
=ISOWEEKNUM(TODAY())
=YEAR(TODAY()-WEEKDAY(TODAY(),3)+3) ' ISO week-year
="W" & TEXT(ISOWEEKNUM(TODAY()),"00")ISOWEEKNUM is supported natively.
=ISOWEEKNUM(TODAY())
=YEAR(TODAY()-WEEKDAY(TODAY(),3)+3)ISO 8601 is the international standard for week numbering. It defines unambiguously when a week starts (Monday) and how week 1 is counted.
Java, C# (>= .NET Core 3), Python (>= 3.9), Go, Ruby, Rust with chrono, and most modern databases (Postgres, MySQL with mode 3, SQL Server 2008+, BigQuery).
Excel's WEEKNUM defaults to the US system. Use ISOWEEKNUM (Excel 2013+) or the Monday-Thursday formula to get ISO 8601.