5

If a question posted is over 24 hours old then I want to limit it to show the day count and not the hours count. Obviously if under 24 hours old then show the hours count.

Currently: Asked 1 day, 18 hours ago

Optimal: Asked 1 day ago

{{question.created|timesince}}

Still fairly new to Django, any help would be appreciated.

Dan
  • 1,536
  • 4
  • 17
  • 31
  • This is answered here: https://stackoverflow.com/a/6495277/3325322 There is no default filter in Django for this so it has to be adapted. – gdvalderrama Mar 18 '20 at 14:20

1 Answers1

3

Have a look at naturaltime: https://docs.djangoproject.com/en/dev/ref/contrib/humanize/#naturaltime

It should give you what you're looking for.

Abid A
  • 7,588
  • 4
  • 32
  • 32
  • 6
    I have the same problem with naturaltime. If it's published 1 week and 3 days ago, it shows 1 week and 3 days, but what I really want is to show 1 week ago. What shall I do to fix this one? – Sarah Akhavan Aug 24 '15 at 07:16