from datetime import date, datetime, timedelta
d = date(2026, 5, 16) # just a date
dt = datetime(2026, 5, 16, 14, 30, 0) # date + time
date.today() # date(2026, 5, 16)
datetime.now() # full timestamp
datetime.strptime("2026-05-16", "%Y-%m-%d")
datetime.strptime("16/05/2026", "%d/%m/%Y")
datetime.strptime("May 16, 2026", "%B %d, %Y")
The format codes are documented at strftime.org. The big ones: %Y year, %m month, %d day, %H hour, %M minute.
d = date.today()
d.isoformat() # '2026-05-16'
d.strftime("%B %d, %Y") # 'May 16, 2026'
d.strftime("%A") # 'Saturday'
today = date.today()
tomorrow = today + timedelta(days=1)
last_week = today - timedelta(weeks=1)
age_days = (today - date(1990, 1, 1)).days # how many days old
from datetime import date
from calendar import monthrange
year = 2026
month_ends = []
for m in range(1, 13):
last_day = monthrange(year, m)[1]
month_ends.append(date(year, m, last_day))
for d in month_ends:
print(d.isoformat())
date = just a date. datetime = date + time.strptime parses; strftime formats.timedelta; .days gives you the day count.Write a script that prints how many days until your next birthday.