difference between dates python code example
Example 1: python calc days between dates
from datetime import date
d0 = date(2008, 8, 18)
d1 = date(2008, 9, 26)
delta = d1 - d0
print(delta.days)
Example 2: Date difference in minutes in Python
minutes_diff = (datetime_end - datetime_start).total_seconds() / 60.0
Example 3: day difference between two dates in python
from datetime import date
d0 = date(2017, 8, 18)
d1 = date(2017, 10, 26)
delta = d1 - d0
print(delta.days)
Example 4: python get dates between two dates
from datetime import datetime, timedelta
def date_range(start, end):
delta = end - start
days = [start + timedelta(days=i) for i in range(delta.days + 1)]
return days
start_date = datetime(2008, 8, 1)
end_date = datetime(2008, 8, 3)
print(date_range(start_date, end_date))