Creating a range of dates in Python

后端 未结 20 2094
栀梦
栀梦 2020-11-22 11:02

I want to create a list of dates, starting with today, and going back an arbitrary number of days, say, in my example 100 days. Is there a better way to do it than this?

20条回答
  •  抹茶落季
    2020-11-22 11:39

    Matplotlib related

    from matplotlib.dates import drange
    import datetime
    
    base = datetime.date.today()
    end  = base + datetime.timedelta(days=100)
    delta = datetime.timedelta(days=1)
    l = drange(base, end, delta)
    

提交回复
热议问题