我编写了一个函数来返回当前会计年度日期:
def get_fiscal_year(start_month=7):
now = datetime.datetime.now()
if now.month >= start_month:
return [time.strptime(str(now.year) + '-07-01', '%Y-%m-%d'), time.strptime(str(now.year + 1) + '-06-30', '%Y-%m-%d')]
return [time.strptime(str(now.year - 1) + '-07-01', '%Y-%m-%d'), time.strptime(str(now.year) + '-06-30', '%Y-%m-%d')]
然后我在我的代码中使用它,如下所示:
dates = get_fiscal_year()
start_date = dates[0]
end_date = dates[1]
model = DevelopmentAssessment.objects.filter(status_id__in=[8, 7, 10], decision_date__range=[start_date, end_date])
但是它抛出了错误:
[u"'time.struct_time(tm_year=2012, tm_mon=7, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=6, tm_yday=183, tm_isdst=-1)' value has an invalid date format. It must be in YYYY-MM-DD format."]
据我所知,它是那种格式,有什么想法吗?
干杯,本