Intermediate·6 min·intermediate · time
Dates & Time
Dates & Time
Three types
date— year/month/daytime— hour/min/secdatetime— both
Arithmetic with timedelta
datetime + timedelta(days=N, hours=H) works as you'd expect.
strftime / strptime
dt.strftime("%Y-%m-%d")— format a datetime → stringdatetime.strptime(s, "%Y-%m-%d")— parse a string → datetime
Format codes: %Y year · %m month · %d day · %H:%M:%S time.
Try it
- How many days until your next birthday?
- Parse
"28/06/2026"(DD/MM/YYYY).