I would like to convert a date into int value, but the int should be the difference of the date and another date that I specifed. To be more clear, let assume that I want to convert the date 15/03/2020 in the int difference between it and the base date, that for example is 02/02/2020. In this case I would obtain 41 as result, cause it is the difference in days between the 2 dates. How can I do it in python?
Asked
Active
Viewed 72 times
1 Answers
1
You might subtract datetime.date
from datetime.date
to get datetime.timedelta
i.e.
import datetime
d1 = datetime.date(2020, 3, 15)
d0 = datetime.date(2020, 2, 2)
diff = (d1-d0).days
print(diff)
Output:
42

Daweo
- 31,313
- 3
- 12
- 25