datetime module

The standard library module for dates and times as real values you can compare, add to and format, not as text.

In more detail

datetime.now() gives the current local date and time and date.today() the date. Subtracting two dates gives a timedelta, and adding a timedelta moves a date forward or back. Convert to and from text with strftime and strptime.

Example

from datetime import date
(date(2026, 12, 25) - date.today()).days

Related terms

Taught in

References