In this python basic program,we will calculate days between 2 dates using datetime library.
Steps to solve the program
- From datetime import date().
- Pass the date() to the given dates.
- Subtract date_2 from date_1 and calculate only days using .days
- Print the output.
from datetime import date
date_1 = date(2023, 1, 5)
date_2 = date(2023, 1, 22)
result = (date_2 - date_1).days
print ("Number of Days between the given Dates are: ", result, "days")
Output :
Number of Days between the given Dates are: 17 days