python time between two datetimes code example
Example 1: get time between things python
>>> import datetime
>>> time1 = datetime.datetime.now()
>>> time2 = datetime.datetime.now()
>>> elapsedTime = time2 - time1
>>> elapsedTime
datetime.timedelta(0, 125, 749430)
>>> divmod(elapsedTime.total_seconds(), 60)
(2.0, 5.749430000000004)
Example 2: 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))