isoweekday() : day of the week as integer, Sunday =0 , Monday =1 ....
Today's isoweekday()
from datetime import date
dt=date.today()
print(dt.isoweekday())
Output
2
Using date and time object
from datetime import datetime
dt=datetime(2019,12,31)
print(dt.isoweekday())
Output
2
Example with weekday()
from datetime import date
dt = date.today()
print(dt.weekday()) # Monday = 0
print(dt.isoweekday()) # Monday = 1
Example 1: Determine if a Date Falls on a Weekend
from datetime import date
dt = date(2024, 9, 14)
if dt.isoweekday() in [6, 7]:
print(f"{dt} is a weekend.")
else:
print(f"{dt} is a weekday.")
Output
2024-09-14 is a weekend.
Example 2: Check Day for Next 7 Days
from datetime import date, timedelta
today = date.today()
for i in range(7):
future_date = today + timedelta(days=i)
print(future_date, future_date.isoweekday())