We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9266 ☆ 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?
      • 3749
      • 24,544 Posts
      I'd try this (untested):

      [[!isNew]]


      /* 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!', '';
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting