Computer >> Computer tutorials >  >> Programming >> Python

How do I calculate number of days between two dates using Python?


You can use simple date arithematic to find the number of days betwen two dates in Python. Define the 2 dates between which you want to find the difference of days. Then subtract these dates to get a timedelta object and examine the days property of this object to get the required result.

Example

from datetime import date
d0 = date(2017, 8, 18)
d1 = date(2017, 10, 26)
delta = d1 - d0
print(delta.days)

Output

This will give the output −

69