Reputation: 325
I have an HTML table in which I am displaying timeuntil
for the difference between two dates.
The code in my template looks like this:
Applied leave from {{pl.start_date}} to {{pl.end_date}} for {{ pl.end_date|timeuntil:pl.start_date }}
My timeuntil
is showing in this way:
Applied leave from Sept. 19, 2017 to Sept. 21, 2017 for 2 days,...
But I need to display 3 days. How can I achieve it?
Upvotes: 2
Views: 391
Reputation: 3483
Can you try this?
Create your own template tag, similar to what I do:
from dateutil import parser
from django import template
register = template.Library()
@register.filter
def day_difference(value, end_day):
start_day_date = parser.parse(value)
end_day_date = parser.parse(end_day)
difference = start_day_date - end_day_date
return difference.days
Then, try to use this excerpt in your HTML template:
{{ pl.start_date|day_difference:pl.end_date }}
Upvotes: 1