We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4002
    • 64 Posts
    Can someone help me out here. i am sure i am overlooking something very obvious, but i am trying to do a filter on a TV date field in the ditto call and cannot get it to work right. i want all docs that have an artcle_date (tvarticle_date to ditto) that are greater than now() to appear in this particular section - but continue to get no results. here is the call:

    [!Ditto? &display=`all` &tpl=`article_dittoTpl` &dateSource=`tvarticle_date` &dateFormat=`%A %B %d, %Y %r` &filter=`tvarticle_date, UNIX_TIMESTAMP(), 4` &sortBy=`tvarticle_date` &sortDir=`desc` &debug=`1`!]

    I have tried the non-UNIX timestamp (CURRENT_TIMESTAMP()) as well and still get no results.

    thanks in advance for any help on this.
    • Is unix_timestamp() or current_timestamp() a PHP function? I can’t find a reference to those, and if they are I believe the syntax is @CODE:unix_timestamp(); ... but I’m probably wrong there... Mark?

      There is time() available: http://www.php.net/manual/en/function.time.php
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 4002
        • 64 Posts
        they are mysql syntax. i was thinking it wanted that for the sql statement. however, i did also try php syntax and could not get date() or time() to work either.
          • 11975
          • 2,542 Posts
          Hi,

          php functions cannot be used as snippet params.
          Create a new snippet with this code for instance

          return time();

          and then use it within your ditto call.

          To embed a snippet inside another one you must use this syntax

          [!Ditto? &filter=`tvarticle_date,[[myTimeSnippet]],3` => which means in ditto language Remove all documents from results where tvarticle_date is less than now.

          :-)
            Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
            • 4002
            • 64 Posts
            ah yeah. thanks for the BGO. it works perfectly now.

            thanks all.
              • 18397
              • 3,250 Posts
              Ditto supports the @EVAL binding to evaluate php expressions in filter clauses. Thus, @EVAL time(); is the correct syntax to get the current unix timestamp ala http://modxcms.com/eval-binding.html. Here is a working example which will retrieve all documents in the last year.

              [!Ditto?parents=`2`&debug=`1`&display=`all`&filter=`createdon,@EVAL return strtotime('-1 year');,6`!]
              


              Also, here is a related thread:
              http://modxcms.com/forums/index.php/topic,16012.0.html
              • Great pointers Mark. Thanks smiley
                  Ryan Thrash, MODX Co-Founder
                  Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                  • 4002
                  • 64 Posts
                  on a somewhat related note, if i wanted to add a default date to this TV (so a date is submitted even if the user does not actually select a date), can I use @EVAL return time() as the expression in the Default value of the TV? I am using this right now and it is not writing a value to the database. It may be that ’@EVAL return time()’ produces a UNIXTIME and I think the TV dates are saved to mysql in non-UNIX time format. do i need to be formatting the ’time()’ value to a non-UNIX date format for the default value?
                    • 18397
                    • 3,250 Posts
                    The default value will be executed when the TV is loaded, not when saved. Thus, the default value would be the current time the tv is loaded.
                      • 25969
                      • 118 Posts
                      I was wondering on this point actually. I hoped the @EVAL thing would work to set the default date TV value to the current date but realised this probably wouldn’t since the field is handled by Tigra so isn’t an actual form field. Anyone know a quick way round this?