Improve your programming skills

Python list of dates between two dates

s_date = datetime.strptime("2020-01-01", "%Y-%m-%d")
e_date = datetime.strptime("2020-01-15", "%Y-%m-%d")

delta = e_date - s_date


for i in range(delta.days + 1):
day = s_date + timedelta(days=i)
l.insert(i, day)
#print(day)

print(l)

or you can define function

from datetime import datetime, timedelta


s_date = datetime.strptime("2020-01-01", "%Y-%m-%d")
e_date = datetime.strptime("2020-01-15", "%Y-%m-%d")

def out_date_range(argStartDate, argEndDate):
delta = argEndDate - argStartDate
l = []
for i in range(delta.days + 1):
day = argStartDate + timedelta(days=i)
l.insert(i, str(day))
# print(day)
return (l)

print(out_date_range(s_date,e_date))

Leave a comment

Your email address will not be published.