-
☆ A M B ☆
- 77 Posts
So I am trying to determine if there is a way I can output the number of days between the current date and the day in which a document is published. Basically what I am trying to do is a "NEW" product badge for an ecommerce site we are working on. The idea is that a "NEW" product is one that was added to the site in the last 30 days. So I would want to make a custom output filter that would determine the number of days.
Has anyone done this before?
I'd try this (untested):
/* isNew snippet */
$now = time();
$pubDate = strtotime($modx->resource->get('published_on');
$datediff = $now - $pubDate;
$diffDays = floor($datediff / (60 * 60 * 24)) * -1;
return $diffDays < 30? 'NEW!', '';