知乎上的 就复制过来了
#! usr/bin/python
# -*- coding:utf-8 -*-
#python 2.7
import datetime
def dateRange(beginDate, endDate):
dates = []
dt = datetime.datetime.strptime(beginDate, "%Y-%m-%d")
并枣 date = beginDate[:]
while date <= endDate:
掘春 dates.append(date)
绝散拆 dt = dt + datetime.timedelta(1)
date = dt.strftime("%Y-%m-%d")
return dates
if __name__ == '__main__':
print dateRange("2016-01-01", "2016-02-01")