Python Dates and Times
A calendar day is three numbers in a fixed order: year, then month, then day. date(2026, 10, 13) is 13 October 2026. The name date lives in the module datetime. That module already comes with the language, so you do not install it on this page, and you do not copy a file into your folder. The import line only brings the name date in. The number 10 means October. It is not the tenth day, and it is not a minute.
from datetime import date
meeting = date(2026, 10, 13)
print(meeting)
print(meeting.day)
The screen shows two lines. The first line is 2026-10-13. print writes the year, then the month, then the day, with a dash between them. Those dashes are not subtraction. The second line is 13. meeting.day is that day number, and it is an integer. It is not 2026, and it is not 10. The 10 stays in the middle of the first line, because that slot is the month. Nothing on this screen is a clock.
from datetime import time
opens = time(9, 30)
print(opens)
print(opens.minute)
The screen shows two lines again. The first line is 09:30:00. time(9, 30) is hour 9 and minute 30. You did not write the seconds, so they are 0. print shows each part as two digits, which is why the hour is 09 and the seconds are 00. The colons are not division. The second line is 30. opens.minute is the integer 30. It is not 9, and it is not the padded hour 09. The extra zero belongs only to the clock line. The minute itself has no leading zero. This program never builds a calendar day, and the first program never builds a clock.
A month numbered 13 does not exist. date(2026, 13, 1) stops, and the name of the stop is ValueError. That line is not in either program. None is not written in its place, and the program does not go on. Months run from 1 through 12. October is 10, so the meeting above is a real day.
The next page is a random number and a calculation. This page only builds one calendar day and one clock time, then reads one piece of each.
One day and one clock
date(2026, 10, 13) shows 2026-10-13, then the day 13. time(9, 30) shows 09:30:00, then the minute 30. Month 13 stops as ValueError. The next page is a random number and a calculation.
🧠 Test Your Knowledge
Test Your Knowledge
Challenge yourself with this interactive quiz and see how well you understand the topic
📝 Instructions
- Read each question carefully
- Select the best answer for each question
- You can retake the quiz as many times as you want
- Your progress will be shown at the top