How to get Number of Days between Two Dates in Python?

Python – Get Number of Days between Two Dates

To get the number of days between two given dates in Python, follow these steps.

Program

In the following program, we take two dates: date_1 and date_2 as date objects, and find the number of days between them.

Python Program

from datetime import date

date_1 = date(2022, 1, 18)
date_2 = date(2022, 2, 14)
diff = date_2 - date_1
num_days = diff.days
print('Number of days :', num_days)
Run Code

Output #1

Number of days : 27

Summary

In this Python Tutorial, we learned how to find the number of days between two given dates, using datetime library.

Related Tutorials

Privacy Policy Terms of Use

SitemapContact Us