I'm trying to find if two DateTimeFields are greater than 2 days difference in a template. Is this possible to do in a template?
+1
A:
Calculation should not be done in the template. Calculate in the view and pass it in as a context variable.
Ignacio Vazquez-Abrams
2010-01-19 03:08:56
+1
A:
There's no built-in way to do this inside a template. You could first calculate the day difference in the view, but I doesn't sound like that's what you want.
The easiest way to do this inside a template would be to write a custom template filter. (Custom template filters are quite a bit easier than creating custom tags, by the way.)
http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#writing-custom-template-filters
Ben Edwards
2010-01-19 03:36:47