If you need to get the week number from a date in Python, call d.isocalendar().week for the ISO week (Monday start), or d.strftime("%U") for a US-style week that starts on Sunday.
People get stuck because the two disagree around New Year. January 1, 2027 is ISO week 53 of 2026, yet %U calls it week 00.
In this tutorial, I’ll show you how to get the week number from a date in Python four ways. Every VS Code screenshot is a real Python 3.12.5 run.
The 2026 Orders We’ll Number by Week
You’ll reuse five online orders from an Austin coffee roaster, saved as orders.py:
# Online orders for an Austin coffee roaster (USD)
ORDERS = [("2025-12-29", 1240.50), ("2026-01-04", 1975.00),
("2026-11-26", 3120.40), ("2026-12-31", 1540.10),
("2027-01-01", 980.60)]
Four of them sit near New Year on purpose, where week rules split. Dates stored as text? Convert the string to a date in Python first.
Method 1: Get the ISO Week Number with Python datetime isocalendar() (Recommended)
ISO 8601 weeks start on Monday, and week 1 holds the year’s first Thursday. Same five orders:
from datetime import date
from orders import ORDERS
for text, _ in ORDERS:
d = date.fromisoformat(text)
iso = d.isocalendar()
print(f"{d:%a %b %d, %Y} ISO year {iso.year} week {iso.week}")
print("This week:", date.today().isocalendar().week)
Output:
Mon Dec 29, 2025 ISO year 2026 week 1
Sun Jan 04, 2026 ISO year 2026 week 1
Thu Nov 26, 2026 ISO year 2026 week 48
Thu Dec 31, 2026 ISO year 2026 week 53
Fri Jan 01, 2027 ISO year 2026 week 53
This week: 48

Thanksgiving (November 26) is week 48, and the last line printed 48 for the current date in Python.
How does this code work?
isocalendar() returns a named tuple of year, week and weekday (Python 3.9+; older code uses [1]). Read .year from it too, not d.year.
Django’s ExtractWeek and PostgreSQL’s EXTRACT(WEEK ...) use the same ISO calendar week. For weekday names, see getting the day of the week in Python.
Method 2: Get the Week of the Year with strftime() %V, %U and %W
Need the week of the year as text for a label? Use a format code. All three on the sample:
from datetime import date
from orders import ORDERS
print("date %G-W%V %U %W")
for text, _ in ORDERS:
d = date.fromisoformat(text)
print(f"{d} {d:%G-W%V} {d:%U} {d:%W}")
Output:
date %G-W%V %U %W
2025-12-29 2026-W01 52 52
2026-01-04 2026-W01 01 00
2026-11-26 2026-W48 47 47
2026-12-31 2026-W53 52 52
2027-01-01 2026-W53 00 00

How does this code work?
%V is the ISO week and %G the ISO year, so pair them. %U starts weeks on Sunday and %W on Monday; days before the first one are week 00.
Important: these are strings. Wrap them in int() before math, as with days between two dates in Python.
Method 3: Get a US-Style Week Number in Python (Sunday Start)
Many US sales reports start weeks on Sunday, with January 1 always in week 1, like Excel’s WEEKNUM() default. Same orders, one function:
from datetime import date
from orders import ORDERS
def us_week(d):
"""Sunday-start week; the week holding Jan 1 is week 1."""
offset = date(d.year, 1, 1).isoweekday() % 7 # Sunday -> 0
return (d.timetuple().tm_yday + offset - 1) // 7 + 1
for text, _ in ORDERS:
d = date.fromisoformat(text)
print(f"{d:%a %m/%d/%Y} US {us_week(d):>2} "
f"ISO {d.isocalendar().week:>2}")
Output:
Mon 12/29/2025 US 53 ISO 1
Sun 01/04/2026 US 2 ISO 1
Thu 11/26/2026 US 48 ISO 48
Thu 12/31/2026 US 53 ISO 53
Fri 01/01/2027 US 1 ISO 53

How does this code work?
isoweekday() % 7 turns Sunday into 0, so offset is how far January 1 sits past Sunday. Add the day of the year, divide by 7, and you get Sunday-to-Saturday weeks.
Text dates like 01/04/2026? See converting a string to datetime in Python.
Method 4: Get the Week Number from a Date in pandas
For a CSV or Excel column, use pandas 3.0.6. Same orders, totaled per ISO week:
import pandas as pd
from orders import ORDERS
pd.options.display.float_format = "${:,.2f}".format
df = pd.DataFrame(ORDERS, columns=["date", "sales"])
df["date"] = pd.to_datetime(df["date"])
iso = df["date"].dt.isocalendar()
df["iso_year"], df["week"] = iso["year"], iso["week"]
print(df)
print(df.groupby(["iso_year", "week"])["sales"].sum())
print("dt.week still there?", hasattr(df["date"].dt, "week"))
Output:
date sales iso_year week
0 2025-12-29 $1,240.50 2026 1
1 2026-01-04 $1,975.00 2026 1
2 2026-11-26 $3,120.40 2026 48
3 2026-12-31 $1,540.10 2026 53
4 2027-01-01 $980.60 2026 53
iso_year week
2026 1 $3,215.50
48 $3,120.40
53 $2,520.70
Name: sales, dtype: float64
dt.week still there? False

How does this code work?
dt.isocalendar() returns year, week and day columns; grouping on year plus week keeps 2026-W53 together. The old Series.dt.week is gone, so hasattr() printed False.
For text dates, convert the pandas column to datetime first.
Which Python Week Number Method Should You Pick?
| Method | Week starts | Jan 1, 2027 | Best for |
|---|---|---|---|
isocalendar().week | Monday | 53 | ISO reports |
strftime("%V") | Monday | “53” | Labels like 2026-W53 |
strftime("%U") | Sunday | “00” | C-style output |
us_week() | Sunday | 1 | US reports, Excel |
I use isocalendar() unless a US report asks for Sunday weeks.
Week Number Gotchas I Hit in Python
Python week numbers look simple until December:
- Wrong year:
d.yearlabels 2027-01-01 “2027-W53”; use the ISO year. - Week 0:
%Uand%Wstart at 00, not 1. - 53-week years: 2026 has 53 ISO weeks.
Once your weekly report runs, keep these date tutorials close:
- Get the week number from a date in TypeScript
- Get the first and last day of a week in TypeScript
- Get the last day of a month in Python
- Subtract days from a date in Python
Questions About Python Week Numbers
How do I get the week number from a date in Python?
Use d.isocalendar().week (ISO) or int(d.strftime("%U")) (Sunday weeks).
How do I get the current week number in Python?
Use date.today().isocalendar().week; on November 26, 2026 it returns 48.
What is the difference between %U, %W and %V?
%U weeks start Sunday, %W weeks Monday (both from 00); %V is the ISO week, paired with %G.
How do I turn a week number back into a date?
Use date.fromisocalendar(2026, 48, 1); it returns Monday, November 23, 2026.
How do I get the week of the year in pandas?
Use df["date"].dt.isocalendar().week; dt.week no longer exists.
Where is date.isocalendar() documented?

Bijay Kumar is a 13-time Microsoft MVP with more than 18 years in software development, and the founder of Python Guides and TSinfo Technologies. He started out building .NET and SharePoint solutions at HP, TCS and KPIT before moving into Python, machine learning and AI, and he also builds web apps with TypeScript and React. He writes the tutorials here himself, and every example is run before publishing so you see the real output. More about Bijay · Microsoft MVP profile · LinkedIn