isoweekday() returns the ISO 8601 weekday number: 1 for Monday up to 7 for Sunday.
It is always weekday() plus one, and it is the third value returned by isocalendar(). The time of day and the time zone do not matter: it only looks at the date fields.
date.isoweekday() is an instance method of datetime.date: call it on an existing object with dot notation, such as day.isoweekday(...). Import the class first, for example from datetime import date. The datetime class has a method with the same name.
Syntax
Call it with no arguments.
python
number = day.isoweekday()
Call
What it does
date(2024, 3, 15).isoweekday()
Returns 5: Friday.
date(2024, 3, 17).isoweekday()
Returns 7: Sunday.
datetime(2024, 1, 1, 23, 0).isoweekday()
Returns 1: Monday.
Weekend test: day.isoweekday() >= 6 is True on Saturday and Sunday.
Print both numbers for a Friday, then the ISO number for a Sunday.
python
from datetime import date
day = date(2024, 3, 15)
print(day.isoweekday())
print(day.weekday())
print(date(2024, 3, 17).isoweekday())
Output
5
4
7
How It Works
Monday is 1. Friday is the fifth ISO day, so the result is 5.
Off by one.weekday() starts at 0, so it returns 4 for the same Friday.
Sunday is 7. The ISO scale ends with Sunday as day 7.
Example 2 — Map Weekday Numbers to Names Without the Locale
Use your own list of names so the output never depends on locale settings. Index with isoweekday() - 1.
python
from datetime import date
NAMES = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
for day in (date(2000, 1, 1), date(2000, 2, 29), date(2038, 1, 19)):
print(day, NAMES[day.isoweekday() - 1])
Output
2000-01-01 Sat
2000-02-29 Tue
2038-01-19 Tue
How It Works
Fixed list. A Python list gives the same English names on every machine, unlike %a.
Shift to zero. Subtracting 1 turns the ISO range 1 to 7 into list indexes 0 to 6.
Famous dates. 1 January 2000 was a Saturday, and 19 January 2038, when 32-bit Unix time overflows, is a Tuesday.
Example 3 — Count Working Days in a Two-Week Range
Build 14 consecutive days and keep the ones with an ISO number of 5 or less.
python
from datetime import date, timedelta
start = date(2024, 3, 1)
days = [start + timedelta(days=i) for i in range(14)]
working = [d for d in days if d.isoweekday() <= 5]
print(len(working))
print(working[0], working[-1])
print(sum(1 for d in days if d.isoweekday() in (6, 7)))
Output
10
2024-03-01 2024-03-14
4
How It Works
Date range. Adding 0 to 13 days to 1 March gives the dates up to 14 March.
Monday to Friday. ISO numbers 1 to 5 are working days, giving 10 of them.
Weekends. Numbers 6 and 7 mark the two Saturdays and two Sundays.
Frequently Asked Questions
1. Sunday is 7.
weekday() returns 0 to 6 starting Monday; isoweekday() returns 1 to 7 starting Monday.
day.isoweekday() >= 6, or day.weekday() >= 5.
Use day.strftime("%A") for the locale name, or index your own list with isoweekday() - 1.
No, it uses the date fields only. Convert an aware datetime to the zone you care about first.