We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36724
    • 13 Posts
    I'm at a loss w/ the following:

    I have a tv "my_date" and a snippet called "now". The snippet just returns the "now" date.

    Now I'm trying to compare those two w/ an output modifier/filter:

    [[*my_date:strtotime:gte=`[[!now:strtotime]]`:then=`do sth.`]]

    The Unix timestamps as outputted by the tv and snippet on time of testing:

    my_date:strtotime = 1391202000

    now:strtotime = 1385144482

    What does modX do? Nothing, at least not outputting the "do sth." as expected.

    What it does when I use lte instead of gte? Outputting "do sth" shocked)

    It does work correctly in other instances when using lte or comparing the dates directly but not here.

      • 3749
      • 24,544 Posts
      Is your snippet returning a timestamp? If so, you need to remove the second :strtotime modifier.

      Actually, I would do the comparison in the snippet, which should be a lot faster, since it skips the parsing of the modifiers in the tag. Something like this:


      [[!DateCheck]]


      <?php
      /* DateCheck snippet */
      $tvDate = $modx->resource->getTVValue('my_date');
      if (  (! empty($tvDate)) &&  (strtotime($tvDate) >= time())  ) {
         return 'do sth';
      } else {
          return '';
      }
      
        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
        • 36724
        • 13 Posts
        Hi Bob,

        thanks a lot for your reply.

        Actually I ended up in using a snippet pretty much like yours.

        I found out before that none of the comparison output filters did work as I expected. The "lte" one produced the right result but probably for the wrong reason.

        I'm still not sure why it isn't working by just using the output comparison filters but I also presume that using a snippet instead of the output filters is much faster as well.