Write a Python program to get days between two dates


The program imports the "datetime" module from the Python Standard Library, which provides classes for working with dates and times. Two date objects, d1 and d2, are created using the datetime.date class. d1 represents the date June 8, 2014, and d2 represents the date June 8, 2022.

The expression d2 - d1 calculates the difference between the two dates, which is a timedelta object representing the number of days between the two dates. Finally, the print function is used to display the result of the subtraction, which is the number of days between the two dates.

Source Code

import datetime
d1 = datetime.date(2014,6,8)
d2 = datetime.date(2022,6,8)
print(d2-d1)

Output

2922 days, 0:00:00

Example Programs