The easiest method I've seen so far is using the Pandas library.
The method is called pandas.date_range()
# we import the library import pandas as pd # We generate the list of dates list_dates = pd.date_range(start="2021-01-01", end="2021-06-01", freq="D")
We pass the start date and the end date as arguments. As you can see we also pass the frequency, here it will be every day from start date until end date.
You can also pass various frequencies to the freq parameter.
The list is available here.
e.g. One of the most useful is month start.
Or even a 10 days frequency.
Instead of passing the frequency, you can also pass the number of periods you want in between those two dates.
# We generate the list of dates list_dates = pd.date_range(start="2021-01-01", end="2021-06-01", periods=30)
Here you are !
You know now how to generate a list of dates in Python using Pandas.