from datetime import date
date_1 = date(2021, 7, 20)
date_2 = date(2021, 8, 23)
num_of_days = (date_2 - date_1).days
print(num_of_days)
Output
34
Here we are using Python datetime module to get the number of days. In the above code example:
We are formatting the date in month/date/year format and then we are calculating the number of days.
Code Example
from datetime import datetime
date_format = "%m/%d/%Y"
date_1 = datetime.strptime('10/25/2021', date_format)
date_2 = datetime.strptime('11/15/2021', date_format)
result = (date_2 - date_1).days
print(result)
Output
21
0 Comments