1
我寫了一個函數返回當前財年的日期:在我的代碼Time模塊 - strptime Django的驗證錯誤
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."]
據我可以告訴它的格式,任何想法是怎麼回事?
乾杯, 本