get dates between two dates python code example
Example 1: 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))
Example 2: python datetime get all days between two dates
from datetime import date, timedelta
sdate = date(2008, 8, 15)
edate = date(2008, 9, 15)
delta = edate - sdate
for i in range(delta.days + 1):
day = sdate + timedelta(days=i)
print(day)