Python Glossary Русский

all Python 3datetimeterm

datetime.date

date

A calendar date (year, month, day) without time. date.today() gives today, weekday() the day of week (0 = Monday).

Syntax

datetime.date(year, month, day)

Weekday numbering trips everyone up: weekday() counts from 0 for Monday, while isoweekday() counts from 1. An impossible date such as date(2024, 2, 31) raises ValueError right in the constructor, so there is no need to validate by hand — just catch it. The object is immutable and has no notion of "plus one month": you can only add a timedelta, that is, days and weeks.

Examples

import datetime
d = datetime.date(2024, 1, 15)
print(d)              # → 2024-01-15
print(d.weekday())    # → 0
print(d.year, d.month)  # → 2024 1

See also

Open in the full glossarydocs.python.orgReport an inaccuracy