Mastering Python Dates helps you write clean and reliable Python code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.
Python Dates Code Example
Python
from datetime import datetime, date, timedelta
now = datetime.now()
print("Now:", now.strftime("%A, %d %B %Y %H:%M"))
new_year = date(now.year + 1, 1, 1)
print("Days until new year:", (new_year - now.date()).days)
deadline = now + timedelta(days=14)
print("Deadline:", deadline.strftime("%d/%m/%Y"))
parsed = datetime.strptime("22-10-2026", "%d-%m-%Y")
print("Parsed weekday:", parsed.strftime("%A"))
Free sign-in required · Google login available
Python Dates Practice Exercises
Check what you learned in “Python Dates”.
/ 3 solved
Fill in the blank
Format the date as day/month/year.
today.strftime("")
✓ Correct!Not quite. Try again.
Multiple choice
Which class represents a duration like 7 days?
✓ Correct!Not quite. Try again.
Code challenge
Create date(2026, 12, 25) and print it with strftime("%d %B %Y").
Write the code in the live editor. Your answer is checked automatically.