How would you format django datetime, so it produces results in task friendly format
23 sec remaining
2 hour 14 minutes remaining
4 days
How would you format django datetime, so it produces results in task friendly format
23 sec remaining
2 hour 14 minutes remaining
4 days
You will find the timeuntil
filter useful.
{{ my_datetime|timeuntil:target_date }}
The above snippet will return the time remaining until target_date
is reached.
timeuntil
Similar to
timesince
, except that it measures the time from now until the given date or datetime. For example, if today is 1 June 2006 and conference_date is a date instance holding 29 June 2006, then{{ conference_date|timeuntil }}
will return "4 weeks".Takes an optional argument that is a variable containing the date to use as the comparison point (instead of now). If
from_date
contains 22 June 2006, then{{ conference_date|timeuntil:from_date }}
will return "1 week".Comparing offset-naive and offset-aware datetimes will return an empty string.
Minutes is the smallest unit used, and "0 minutes" will be returned for any date that is in the past relative to the comparison point.