Python Glossary Русский

all Python 3calendarfunction

calendar.weekday()

dates and leap years

Returns the day of the week for a date: 0 is Monday, 6 is Sunday.

Syntax

calendar.weekday(year, month, day)

Counting always starts on Monday and ignores setfirstweekday(). It differs from date.isoweekday(), where Monday is 1 and Sunday is 7. A bad month raises a plain ValueError, not IllegalMonthError. Since 3.12 the result is a calendar.Day member, so it has a .name.

Examples

import calendar
print(calendar.weekday(2024, 10, 7))  # → 0 — понедельник
print(calendar.weekday(2024, 10, 13) == calendar.SUNDAY)  # → True
# Python 3.12+
import calendar
print(calendar.weekday(2024, 10, 7).name)  # → MONDAY

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy