datetime Module

say it: “DAYT-tym MOJ-ool” /ˈdeɪttaɪm ˈmɒdʒuːl/

A standard module for working with dates and times.

What is the datetime module?

The datetime module works with dates and times: today's date, how many days until an event, formatting a date for a receipt.

from datetime import date
trip = date(2026, 12, 20)
days_left = (trip - date.today()).days
print(f"{days_left} days until the trip")

Level: Journeyman · More Python terms at this level

Updated