I want to generate a list of dates between two dates and store them in a list in string format. This list is useful to compare with other dates I have.
My code is given below:
from datetime import date, timedelta
sdate = date(2019,3,22) # start date
edate = date(2019,4,9) # end date
def dates_bwn_twodates(start_date, end_date):
for n in range(int ((end_date - start_date).days)):
yield start_date + timedelta(n)
print(dates_bwn_twodates(sdate,edate))
My present output:
<generator object dates_bwn_twodates at 0x000002A8E7929410>
My expected output:
['2019-03-22',.....,'2019-04-08']
Something wrong in my code.
yield
means that your function will return a generator. If you want to run the generator to get all of the elements, you can doprint(list(dates_bwn_twodates(sdate, edate)))
. – Couchantprint(round(df["value"].min(), -2))
andprint(round(df["value"].max(), -2) + 100)
– Mob