from datetime import datetime, timedelta
defdate_range(start, end):
delta = end - start # as timedelta
days =[start + timedelta(days=i)for i inrange(delta.days +1)]return days
start_date = datetime(2008,8,1)
end_date = datetime(2008,8,3)print(date_range(start_date, end_date))
from datetime import date, timedelta
sdate = date(2008,8,15)# start date
edate = date(2008,9,15)# end date
delta = edate - sdate # as timedeltafor i inrange(delta.days +1):
day = sdate + timedelta(days=i)print(day)
# Timedelta function demonstrationfrom datetime import datetime, timedelta
# Using current time
time_for_now = datetime.now()# printing initial_dateprint("initial_date",str(time_for_now))# Some another datetime
new_final_time = time_for_now +
timedelta(days=2)# printing new final_dateprint("new_final_time",str(new_final_time))# printing calculated past_datesprint('Time difference:',str(new_final_time - time_for_now))