成都创新互联网站制作重庆分公司

django如何计算日期

云计算

这篇文章主要介绍了django如何计算日期,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。

创新互联坚持“要么做到,要么别承诺”的工作理念,服务领域包括:网站设计、成都做网站、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的延长网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!importdatetime,timedeltaimportcalendarnow=datetime.now()today=datetime.now().date()#今日ifdays=="1":quesryset=DailyReport.objects.filter(createdate__gte=str(today)+'00:00:00')#昨天elifdays=="2":end=(now+timedelta(days=-1)).date()quesryset=DailyReport.objects.filter(createdate__gte=str(end)+'00:00:00',createdate__lte=str(end)+'23:59:59')#本周elifdays=="3":end=(now+timedelta(days=-now.isoweekday())).date()quesryset=DailyReport.objects.filter(createdate__gte=str(end)+'00:00:00',createdate__lte=str(today)+'23:59:59')#上周elifdays=="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)+'00:00:00',createdate__lte=str(today)+'23:59:59')#本月elifdays=="5":end=(now-timedelta(days=now.day)).date()quesryset=DailyReport.objects.filter(createdate__gte=str(end)+'00:00:00',createdate__lte=str(today)+'23:59:59')#上月elifdays=="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)+'00:00:00',createdate__lte=str(today)+'23:59:59')#过去七天elifdays=="7":end=(now-timedelta(days=7)).date()quesryset=DailyReport.objects.filter(createdate__gte=str(end)+'00:00:00',createdate__lte=str(today)+'23:59:59')#过去30天elifdays=="8":end=(now-timedelta(days=30)).date()quesryset=DailyReport.objects.filter(createdate__gte=str(end)+'00:00:00',createdate__lte=str(today)+'23:59:59')

感谢你能够认真阅读完这篇文章,希望小编分享的“django如何计算日期”这篇文章对大家有帮助,同时也希望大家多多支持箭头云,关注箭头云行业资讯频道,更多相关知识等着你来学习!


网页标题:django如何计算日期
分享地址:http://cxhlcq.com/article/cgiggi.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部