TIMEX TIMEX - 4 years ago 94
Python Question

Is there a Django template filter that turns a datetime into "5 hours ago" or "12 days ago"?

Let's say I have a datetime. I do this:

Submitted on {{ post.date|date:"D. M d, P" }}


This actually prints the date. However, what if I want it to say, "4 hours ago" or "55 days ago" or "2 months ago"?

Answer Source

Try the template filter timesince.

Use it like this:

{{ mytemplatevar|timesince }}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download