Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django datetime task friendly format

Tags:

django

How would you format django datetime, so it produces results in task friendly format

23 sec remaining
2 hour 14 minutes remaining
4 days
like image 638
bobsr Avatar asked Feb 13 '26 23:02

bobsr


1 Answers

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.

like image 125
Manoj Govindan Avatar answered Feb 15 '26 23:02

Manoj Govindan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!