all Python 3datetimefunction
datetime.date.weekday()
datetime methods
Returns the day of the week as an integer: 0 is Monday, 6 is Sunday. Convenient in conditions and for filtering by day.
Syntax
date.weekday() -> int # 0=Mon … 6=Sun
Two neighbouring numbering schemes invite mistakes: isoweekday() returns 1-7 with Sunday as 7, while strftime('%w') returns 0-6 but counts Sunday as zero. A weekend check is safest written as d.weekday() >= 5. The numbering itself is locale-independent — the locale only affects the textual %A and %a.
Examples
from datetime import date
d = date(2024, 6, 17) # понедельник
print(d.weekday()) # 0
print(d.strftime('%A')) # Monday
# фильтр рабочих дней
if d.weekday() < 5:
print('будний день')
See also
Open in the full glossarydocs.python.orgReport an inaccuracy