Python Date and Time Quiz: 20 MCQs with Answers

Python Date & Time Interactive Quiz

Test your knowledge of Python date and time handling using the datetime module, dates, times, timedeltas, formatting, parsing, and practical date and time operations.

What Are Date and Time Operations in Python?

Python provides the datetime module for working with dates and times. It allows programs to create dates, work with times, calculate differences between dates, format date and time values, and convert strings into date and time objects.

This quiz covers:

  • Python datetime module
  • date objects
  • time objects
  • datetime objects
  • timedelta
  • Current date and time
  • Date arithmetic
  • Formatting dates with strftime()
  • Parsing strings with strptime()
  • Practical date and time examples

Take this quiz to test your Python Date & Time knowledge and improve your ability to work with dates and times in Python programs.

📌 Quick Summary

Python Date & Time Quiz: Test your knowledge with 20 interactive multiple-choice questions covering the datetime module, date and time objects, timedelta, formatting, parsing, and practical examples.

  • 20 Python Date & Time MCQs
  • 160-second interactive quiz
  • Answer explanations included
  • Suitable for Python beginners and intermediate learners
  • Includes output-based questions

⏱ Time Left: 160 seconds

Q1. Which Python module is commonly used for working with dates and times?





Q2. Which statement correctly imports the datetime module?





Q3. Which class represents a date containing year, month, and day?





Q4. Which expression returns the current local date?





Q5. Which expression returns the current local date and time?





Q6. What is the output?


  from datetime
  import date 
  d = date(2026, 9, 4) 
  print(d.year)




Q7. Which class is used to represent a time independently of a date?





Q8. What does a datetime object generally contain?





Q9. Which class is used to represent a duration or difference between dates or times?





Q10. What is the output?


  from datetime
  import date, timedelta
  d = date(2026, 9, 4) 
  new_date = d + timedelta(days=5)
  print(new_date)




Q11. Which method converts a date or datetime object into a formatted string?





Q12. What does the %Y directive represent in strftime()?





Q13. What is the output?


  from datetime
  import date
  d = date(2026, 9, 4)
  print(d.strftime("%d-%m-%Y"))




Q14. Which method is used to parse a string into a datetime object using a specified format?





Q15. What is the result of this code?


  from datetime
  import datetime
  d = datetime.strptime("04-09-2026", "%d-%m-%Y")
  print(d.year)




Q16. Which attribute returns the month from a date object?





Q17. What is the output?


  from datetime
  import date
  d1 = date(2026, 9, 4)
  d2 = date(2026, 9, 10)
  print((d2 - d1).days)




Q18. Which expression creates a date representing September 4, 2026?





Q19. Which statement correctly describes strftime() and strptime()?





Q20. Why is the Python datetime module useful?







Why Is Python Date & Time Handling Important?

Ans: Date and time operations are important in many Python applications. The datetime module makes it possible to work with calendar dates, timestamps, durations, scheduling, and formatted date strings.

  • Work with current dates and times
  • Calculate differences between dates
  • Add or subtract days and time periods
  • Format dates for display
  • Parse dates received as strings
  • Build scheduling and reminder applications
  • Work with timestamps and time-based data

❓ Frequently Asked Questions About Python Date & Time

What is the datetime module in Python?

The datetime module is a Python standard library module that provides classes for working with dates and times.

How do you get today's date in Python?

You can use date.today() to obtain the current local date.

How do you get the current date and time in Python?

The datetime.now() method can be used to obtain the current local date and time.

What is timedelta in Python?

timedelta represents a duration or difference between dates or times. It can be used to add or subtract periods such as days, seconds, and weeks.

What is strftime() in Python?

strftime() formats a date or datetime object into a string according to specified formatting codes.

What is strptime() in Python?

strptime() parses a string representing a date or time and converts it into a datetime object using a specified format.

What is the difference between date and datetime in Python?

A date object represents a calendar date, while a datetime object contains both date and time information.

Can Python calculate the difference between two dates?

Yes. Subtracting one date from another produces a timedelta object, which can be used to determine the difference between the dates.


📚 Continue Learning and Testing Your Python Knowledge Step by Step:


Featured Post

Python Date and Time Quiz: 20 MCQs with Answers

Python Date & Time Interactive Quiz Test your knowledge of Python date and time handling using the datetime module, dates, time...

Popular Posts