Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate number of days between two dates inside Django templates

Tags:

python

django

I have two dates and want to show a message like "n days left before your trial end." where n is a number of days between two given dates. Is that better to do this inside views or is there a quick way to do it inside template itself?

like image 483
Sergei Basharov Avatar asked Oct 25 '11 10:10

Sergei Basharov


2 Answers

Use timesince template tag.

like image 54
spicavigo Avatar answered Oct 10 '22 02:10

spicavigo


This code for HTML in Django. You can easily find the remaining days.

{{ to_date|timeuntil:from_date }}

Otherwise, you can use custom TemplateTags.

like image 21
jahurul25 Avatar answered Oct 10 '22 01:10

jahurul25