Friday, May 6, 2011

"x Days ago' template filter in Django?

I'm looking for a filter that turns a datetime instance into 'x Days' or 'x years y months' format (as on SO). Suggestions? Am I overlooking something very obvious?

From stackoverflow
  • Have a look at the timesince template filter. It's builtin.

    The following returns a humanized diff between now and comment_date (e.g. '8 hours'):

    {{ comment_date|timesince }}
    

    The following returns a humanized diff between question_date and comment_date:

    {{ comment_date|timesince:question_date }}
    
    Yuvi : Thanks, just what I was looking for :) /me should've read the docs better

0 comments:

Post a Comment