Get All Dates Between Two Dates Inclusive in Python


If you want to print out a list of all dates between 2 dates (a date range), then you can use the following script:

from datetime import date, timedelta

start_date = date(2021, 5, 31)
end_date = date(2021, 7, 28)

delta = end_date - start_date

for i in range(delta.days + 1):
    day = start_date + timedelta(days=i)
    print(day)

This will result in the following range:

2021-05-31
2021-06-01
...
2021-07-27
2021-07-28

To make sure that you get the format you want back:

day.strftime("%Y-%m-%d")