I use javascript to do this sort of thing eg. in your template call javascript function eg.
<div> result = yearsBeforeToday('{{ model.date|date:"Y-m-d H:i:s" }}'); </div> yearsBeforeToday is javascript function, does all the calculation for your date. model.date is the date value you are getting from the view that's calling the template. gath On May 13, 9:47 pm, Michael Radziej <m...@noris.de> wrote: > On Wed, May 13, Joshua Partogi wrote: > > Dear all, > > > Is it possible to do time and or date calculation in the template? > > > Let's say I have a DateField {% now %} and want to subtract it with an > > IntegerField (let's say 4, to get 4 years before today) in the template. If > > it's possible, what is the syntax for it? > > There's no simple way. You could write an template tag or filter. > > http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#howt... > > Or you could do the calculation in the view and put it into the context. > > Michael --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---