The Datetime Module
Alright, young developer — you have survived the math toolbox and unleashed the chaos of the random module.
Feeling confident?
Feeling unstoppable?
Feeling like you could code your own AAA game tomorrow?
Nice! Let’s give you some Python time-bending jiu-jitsu so your game can actually tell time like a responsible adult. Because timers, countdowns, and “You finished in 12.4 seconds!” don’t magically appear out of thin air.
STEP 3: Teaching Your Game to Know What Time It Is
Python has a toolbox called datetime, and it’s basically your game’s personal clock, calendar, and timekeeper.
You can use it to:
- Show today’s date
- Display the current time
- Build countdown timers
- Track how long a player takes to finish a level
- Schedule daily challenges (yes, you’re that advanced now)
Let’s open the toolbox.
This means: “Python, hand me the time-control tools. I’m about to do some chrono-magic.”
STEP 3A: Getting Today’s Date
import datetime
today = datetime.date.today()
print("Today's date is:", today)
What’s happening?
- datetime.date.today(): Python checks the calendar.
- today: You store the date in a variable.
- print(…): Shows it on the screen.
Useful for:
- daily login rewards
- streak tracking.
- “Come back tomorrow for a new puzzle!”
STEP 3B: Getting the Current Time
import datetime
now = datetime.datetime.now()
print("Current time:", now.strftime("%H:%M:%S"))
What’s happening?
- datetime.datetime.now(): Python grabs the exact moment you ran the code.
- strftime(“%H:%M:%S”): Formats it into a clean time like: 14:32:10 (24 hour clock because we’re professionals here.) .
Perfect for:
- speed run timers
- countdowns.
- “You took 9.2 seconds to guess the word!”
Practice (Your Turn!)
Mini Challenge 1: Start Time Message
Add a line that prints:
Your game started at: <current time>
Hint: Use the now variableMini Challenge 2: Day of the Week
Use: today.strftime("%A")
This gives you:
- Monday
- Tuesday
- Wednesday
- etc.
Print something like:
Today is: WednesdayBut let Python figure out the day — don’t type it manually unless you enjoy lying to your code.

