首页 > 代码库 > Python2 获取两日期之间的每一天

Python2 获取两日期之间的每一天

import datetime
def getEveryDay(begin_date,end_date):
    date_list = []
    begin_date = datetime.datetime.strptime(begin_date, "%Y-%m-%d")
    end_date = datetime.datetime.strptime(end_date,"%Y-%m-%d")
    while begin_date <= end_date:
        date_str = begin_date.strftime("%Y-%m-%d")
        date_list.append(date_str)
        begin_date += datetime.timedelta(days=1)
    return date_list
print getEveryDay(2016-01-01,2017-05-11)

 

不定时更新,待续。。。

Python2 获取两日期之间的每一天