日期时间比较在django模板 [英] DateTime compare in django template
本文介绍了日期时间比较在django模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在模型中有一个日期字段:
date_created = models.DateTimeField(auto_now = True)
我想比较date_created到今天的日期。所以这就是我在django模板中所做的工作:
{%if x.for_meeting.date_created<今天%}#(x是MeetingRecord类的实例,其中for_meeting字段是会议表的外键where date_created)
现在我正在计算今天的视图,如:
today = datetime.now()。strftime(%B% d,%Y,%I:%M%P)
不幸的是我无法比较日期。
请告诉我这里有什么错误。
解决方案
today = datetime.now()
{ %if x.for_meeting.date_created.date< today.date和x.for_meeting.date_created.time< today.time%}
I am having a problem while comparing two dates in Django templates.
I have a date field in my model:
date_created = models.DateTimeField(auto_now=True)
I want to compare date_created by today date. So this is what I am doing in my django template:
{% if x.for_meeting.date_created < today%} # (x is the instance of MeetingRecord class where for_meeting field is Foreign key to Meeting table Where date_created)
Now I am calculating today in view like:
today = datetime.now().strftime("%B %d, %Y,%I:%M %P")
Unfortunately I am not able to compare the dates.
Please tell me what might I am doing wrong here.
解决方案
today = datetime.now()
{% if x.for_meeting.date_created.date < today.date and x.for_meeting.date_created.time < today.time %}
这篇关于日期时间比较在django模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文