How do I calculate the time difference in a Django template

rsp picture rsp · Feb 14, 2014 · Viewed 9.2k times · Source

I have a model with two TimeFields. I want to show the time difference in a template (ie, 27 minutes). I see the filter timesince, but it isn't working; I think it only accepts datetimes but my models have stored times only.

Response to @HAL:

'datetime.time' object has no attribute 'year'
Exception Location: C:\Python27\lib\site-packages\django\utils\timesince.py in timesince, line 32

Answer

Yogesh dwivedi Geitpl picture Yogesh dwivedi Geitpl · Feb 14, 2014

You can use timesince template tag.