Working with time in Python starts with the datetime module. It gives
you a datetime type for a full moment (date plus time) and a date
type for a calendar day on its own.
from datetime import datetime, date
datetime.now() returns the current local date and time as a
datetime object:
now = datetime.now()
print(now) # 2026-07-24 14:03:51.412000
date.today() gives just today's calendar date:
date.today() # 2026-07-24
Pass year, month, and day (and optionally hour, minute, second) to construct an exact value:
released = datetime(2026, 3, 1, 9, 30, 0)
deadline = date(2026, 7, 30)
Every datetime and date exposes its fields as attributes:
now = datetime.now()
now.year # 2026
now.month # 7
now.day # 24
now.hour # 14
These are plain integers, so you can compare them, print them, or feed them into other calculations.
datetime.now() returns the current date and time.date.today() returns the current calendar date.datetime(y, m, d, ...) and date(y, m, d) build specific values..year, .month, .day, .hour read the parts.