"""
获取当前月的前x月月份日期
"""
import datetime
def getTheMonth(date, n):
month = date.month
year = date.year
for i in range(n):
if month == 1:
year -= 1
month = 12
else:
month -= 1
return datetime.date(year, month, 1).strftime('%Y-%m')
date = datetime.datetime.today()
single_time_new = getTheMonth(date, 5)
single_time_old = getTheMonth(date, 6)
import datetime
# 根据开始日期、结束日期返回这段时间里所有天的集合
def getDatesByTimes(sDateStr, eDateStr):
list = []
datestart = datetime.datetime.strptime(sDateStr, '%Y-%m-%d')
dateend = datetime.datetime.strptime(eDateStr, '%Y-%m-%d')
list.append(datestart.strftime('%Y-%m-%d'))
while datestart < dateend:
datest