3

I'd like to reopen this question:

The answer was a plugin called Nice Time

But This plugin is depricated and the creator stats that this functionality is acheivable via the date_modify filter.

Yes okay, but how?

I have a event archive where I want to show "This event happend xy days ago".

There is a time_diff filter in twig. But it seems as if this is not activated in craft.

KSPR
  • 3,786
  • 2
  • 29
  • 52

2 Answers2

6

You could use the diff method to get the number of days between two dates. So for example:

{{ date(entry.dateCreated|date('c')).diff(now).days }} days ago

In my example between today (using now) and the entry.dateCreated.

There is a explanation as to why you need to wrap the first date in the date filter here, which is where I got the answer from!

Steve Holland
  • 2,485
  • 1
  • 16
  • 31
3

I have a plugin that adds the time_diff Twig filter to Craft:

https://github.com/mildlygeeky/craft-timediff

There is one possible issue (in either PHP or Craft) around DST, and I will add that to the README.

Patrick Harrington
  • 1,080
  • 6
  • 9