Check if the date matches in the future

How can I check from a Django template whether this date will be in the future?

Sort of:

{% if event.date > now %} 
+4
source share
1 answer

Write a function in an event named in_future that will compare event.date with datetime.now() and use it in the template. Do not add unnecessary logic to the template.

Or, as Manoah suggested, you can create your own in_the_future filter and call it:

 {% if event.date|in_the_future %} 

It's simple:

 @register.filter def in_the_future(value): return value > datetime.now() 
+3
source

All Articles