Filter "x days ago" templates in Django?

I'm looking for a filter that converts a datetime instance to "x Days" or "x years y months" format (like on SO). Suggestions? Can I ignore something very obvious?

+10


a source to share


1 answer


Take a look at the timesince filter pattern . It's built in.

The following returns a humanized diff between now and comment_date

(for example '8 hours'

):

{{ comment_date|timesince }}

      



The following returns a humanized distinction between question_date

and comment_date

:

{{ comment_date|timesince:question_date }}

      

+27


a source







All Articles