Generating all dates within a given range in python

前端 未结 9 554
青春惊慌失措
青春惊慌失措 2021-02-02 08:31

I have two string variables which contain dates in yyyy-mm-dd format as follows :

date1 = \'2011-05-03\'
date2 = \'2011-05-10\'

I want to write

9条回答
  •  说谎
    说谎 (楼主)
    2021-02-02 09:15

    >>> for a in range(9):
    ...     print(datetime.date(2011, 05, 03) + datetime.timedelta(a))
    ...
    2011-05-03
    2011-05-04
    2011-05-05
    2011-05-06
    2011-05-07
    2011-05-08
    2011-05-09
    2011-05-10
    2011-05-11
    

    I'm not too sure whether the parsing of the strings was integral or just the way you started the question. If so, please disregard the answer as oversimplified

提交回复
热议问题