Home › Python with Chai › Lesson 18
datetime: shop timing
Python with Chai, lesson 18 of 20. A short Hinglish video, simple English notes and code you can run, free.
Open the interactive lesson with Run button
The idea
datetime is Python's clock. from datetime import datetime brings it in, and datetime.now() gives the date and time right now.
strftime() formats it: "%H:%M" gives 09:30, "%d-%m-%Y" gives 18-10-2026.
now.hour is just the hour (0–23), so you can decide things: is the shop open?
The code
from datetime import datetime
now = datetime.now()
print(now.strftime("%d-%m-%Y %H:%M"))
if 8 <= now.hour < 22:
print("Dukaan khuli hai!")
else:
print("Kal aana!")
Output:
18-10-2026 09:30 Dukaan khuli hai! (your date and time will be different)
Try it yourself
- Print just the day name with now.strftime("%A").
- Change the hours so the shop opens at 7 and closes at 11 at night.
Remember
datetime = Python's clock: now(), strftime(), hour.
← Sets: how many customers? · Classes: the chai shop →
All lessons: Python with Chai