Editor

Calculate Days Between Dates

Beginner · Write the code · from Python datetime: Dates, Times, Timezones, and Calculations

From the lesson: Python datetime: Dates, Times, Timezones, and Calculations

Think about your phone. It shows the current time, tracks your calendar events, and reminds you about birthdays. Behind the scenes, all of that runs on date and time calculations.

Read the lesson

Calculate how many days are between January 1, 2024 and March 15, 2024. Print just the number of days.

from datetime import date
# Calculate days between Jan 1 and March 15, 2024

More datetime exercises

All Python exercises · 50 practice problems · Standard Library Essentials quiz