Exercises
Dates
3 tasks. Write the code, press Check, and the page runs it against a real Python interpreter.
Exercise 1Passed
Print the 14th of March 2026 formatted as day/month/year.
Python
from datetime import date
# print 14/03/2026
strftime with %d, %m and %Y.
from datetime import date
print(date(2026, 3, 14).strftime("%d/%m/%Y"))Exercise 2Passed
Print how many days there are between the two dates.
Python
from datetime import date
start = date(2026, 3, 1)
end = date(2026, 3, 14)
# print the number of days
Subtracting two dates gives a timedelta with a days attribute.
from datetime import date
start = date(2026, 3, 1)
end = date(2026, 3, 14)
print((end - start).days)Exercise 3Passed
Read the ISO date text into a date object and print its year.
Python
from datetime import date
text = "2026-03-14"
# print the year as a number
date.fromisoformat needs no format string.
from datetime import date
text = "2026-03-14"
print(date.fromisoformat(text).year)