Time is a river, but for a coder, it's just numbers. The datetime scroll lets us freeze time, travel to the future, and measure the past.
Hoppy needs to know exactly when the "Great Migration" begins.
The datetime Spell
This scroll is powerful. It has spells for dates (Year-Month-Day) and precise times (Hour:Minute:Second).
import datetime # What day is it? today = datetime.date.today() print(today) # e.g., 2025-10-24 # Create a specific date halloween = datetime.date(2025, 10, 31) # Time travel! (Math with dates) days_left = halloween - today print(days_left.days) # 7
Use datetime.date.today() to capture the current moment.
The Great Migration is set for January 1st, 2030. create a date object for it: datetime.date(2030, 1, 1).
Subtract today from migration_day. Python is smart enough to know this creates a "Time Delta" (difference). Print the .days property of the result.
Programmers count time in weird ways. Sometimes we count seconds from 1970 (Unix Epoch), but datetime makes it human-readable!
Suggested SolutionExpandCollapse
import datetime
# Step 1: Today
today = datetime.date.today()
print("Today: " + str(today))
# Step 2: Migration Day (2030-1-1)
migration_day = datetime.date(2030, 1, 1)
# Step 3: Calculation
time_left = migration_day - today
print("Days until migration: " + str(time_left.days))Advanced TipsWant more? Click to expandClick to collapse
F. Timezones (The Horror)
datetime.dateis simple. But dealing with timezones (like UTC vs EST) is one of the hardest things in programming.- Lucky for Hoppy, Pythondia only has one timezone!