How does django calculate the date
This article mainly introduces django how to calculate the date, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
Import datetime,timedeltaimport calendarnow = datetime.now () today = datetime.now (). Date () # Today if days= = "1": quesryset = DailyReport.objects.filter (createdate__gte=str (today) + '00lv 00') # yesterday elif days= = "2": end = (now + timedelta (days=-1)). Date () quesryset = DailyReport.objects.filter (createdate__gte=str (end) +' 00lv 0000' Createdate__lte=str (end) + '23elif days= 59end 59') # this week elif days= = "3": end = (now + timedelta (days=-now.isoweekday ()). Date () quesryset = DailyReport.objects.filter (createdate__gte=str (end) +' 00lv 00' Createdate__lte=str (today) +'23 timedelta 59 end 59) # Last week elif days= = "4": end = (now-timedelta (days=7 + now.isoweekday ()). Date () today = (now-timedelta (days=now.isoweekday () + 1)). Date () quesryset = DailyReport.objects.filter (createdate__gte=str (end) + '00Vue 00' Createdate__lte=str (today) + '23elif days= 59end) # this month elif days= = "5": end = (now-timedelta (days=now.day)). Date () quesryset = DailyReport.objects.filter (createdate__gte=str (end) +' 0000VOV, createdate__lte=str (today) + '23Vl59)) # Last month elif days= = "6": last_month = now-timedelta (days=now.day) end_month_days = calendar.monthrange (last_month.year) Last_month.month) [1] end = (last_month-timedelta (days=end_month_days)) .date () today = (now-timedelta (days=now.day+1)) .date () quesryset = DailyReport.objects.filter (createdate__gte=str (end) + '00timedelta 0000' Createdate__lte=str (today) +'23 elif days= 59 end 59) # in the past seven days elif days= = "7": end = (now-timedelta (days=7)) .date () quesryset = DailyReport.objects.filter (createdate__gte=str (end) +'00 end 00' Createdate__lte=str (today) +'23 end 59 end 59) # over the past 30 days, elif days= = "8": end = (now-timedelta (days=30)). Date () quesryset = DailyReport.objects.filter (createdate__gte=str (end) + '0000 end) +' 0000 end, createdate__lte=str (today) +'23 end 59) Thank you for reading this article carefully I hope the article "how to calculate the date of django" shared by the editor will be helpful to you. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!