We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36782
    • 109 Posts
    Hi,
    I'm wondering about this type of thing:
    ...DATE_SUB(NOW(), INTERVAL 60 DAY) > publishedon...


    ... in a getResources &where parameter?

    I wrote that off the top of my head - I'm not great with these type of calculations; basically I want to get resources where their published date is older than 60 days.

    Anyone got any clues on this?
    Should I maybe write a snippet and use that as the parameter, so that I can just use SQL? hmmmmm.....
      • 19604 ☆ A M B ☆
      • 179 Posts
      Quote from: unsub777 at Feb 03, 2013, 05:45 PM
      Anyone got any clues on this?
      gR output depending on a date is possible. Can be used for events, like "upcoming" or "see it now". The math-date thing my require a snippet, but I am not sure.
      Since the manager does not like the iPad, I can only go into details by tomorrow, when I am at the desktop again. ;-)
        MINDEFFECTS – DESIGN for PRINT, WEB and MEDIA
        http://twitter.com/mindeffects · http://www.facebook.com/mindeffects · http://www.youtube.com/mindeffects/ · skype://mindeffects_oliver
        • 36782
        • 109 Posts
        cheers smiley glad to know it's possible.
        I might play around with it a bit today; I suppose I could use some output modifiers in the template to only show the gR results from beoyond a certain point... I don't know, it seems like I'm missing something obvious. I'm going to have a facePalm moment sometime today, almost certainly.
        Any insight you have will be much appreciated. thnx!
        Quote from: mindeffects at Feb 03, 2013, 06:49 PM
        Quote from: unsub777 at Feb 03, 2013, 05:45 PM
        Anyone got any clues on this?
        gR output depending on a date is possible. Can be used for events, like "upcoming" or "see it now". The math-date thing my require a snippet, but I am not sure.
        Since the manager does not like the iPad, I can only go into details by tomorrow, when I am at the desktop again. ;-)
          • 22303 MODX Staff
          • 10,725 Posts
          <?php
          /* stringToTime snippet */
          return strtotime($input);
          

          &where=`{"publishedon": [[!stringToTime? &input=`-60 days`]] }`


          If you have a Setting (from System or Context or User) that you want to use, you don't need the custom snippet as there is a strtotime output filter built-in to the MODX core:
          &where=`{"publishedon": [[!++publishedon_time_setting:strtotime]] }`


          You might combine this with getCache to prevent re-evaluation on every request (e.g. cache the output of getResources for 1 day).
            • 19604 ☆ A M B ☆
            • 179 Posts
            Quote from: unsub777 at Feb 04, 2013, 12:11 PM
            cheers smiley glad to know it's possible.
            I might play around with it a bit today; I suppose I could use some output modifiers in the template to only show the gR results from beoyond a certain point... I don't know, it seems like I'm missing something obvious. I'm going to have a facePalm moment sometime today, almost certainly.
            Any insight you have will be much appreciated. thnx!

            A simple "Is a movie playing in the cinemas now?" could be done by storing the realease date in a date-TV, e.g. "cinemaReleaseDate":

            <h2>Noy playing in the cinemas</h2>
            [[!getResources?
            &parents=`2`
            &tvFilters=`cinemaReleaseDate<=[[!dateToday]]%`
            &sortbyTV=`cinemaReleaseDate` &sortdirTV=`DESC`
            &includeTVs=`1`
            &tpl=`movieListCinema`
            ]]
            </div>


            The "%" in tvFilters makes the system ignore the time, which is, unfortunately, allways stored, too.

            The snippet "dateToday" is quite simple:
            <?php
            return date("Y-m-d");


            Jason/opengeek allready gave you something to achieve your "60 days" target.
              MINDEFFECTS – DESIGN for PRINT, WEB and MEDIA
              http://twitter.com/mindeffects · http://www.facebook.com/mindeffects · http://www.youtube.com/mindeffects/ · skype://mindeffects_oliver
              • 36782
              • 109 Posts
              Hi there,

              @opengeek: Thanks!
              I changed it slightly:
              &where=`{"publishedon:<":[[!stringToTime? &input=`-60 days`]]}`

              It appears to work smiley

              Is there a facePalm emoticon?

              @mindEffects: Appreciate your example there, thank you. That may come in handy for something else I'm working on, actually smiley I never knew the % filter.
                • 19604 ☆ A M B ☆
                • 179 Posts
                Quote from: unsub777 at Feb 04, 2013, 03:45 PM
                @mindEffects: Appreciate your example there, thank you. That may come in handy for something else I'm working on, actually smiley I never knew the % filter.
                Nice having been able to help you here.
                .
                The % is an SQLisch thing: Matches any number of characters, even zero characters. This translates to " just ignore the time".
                  MINDEFFECTS – DESIGN for PRINT, WEB and MEDIA
                  http://twitter.com/mindeffects · http://www.facebook.com/mindeffects · http://www.youtube.com/mindeffects/ · skype://mindeffects_oliver
                  • 36782
                  • 109 Posts
                  @openGeek:
                  Just a quick follow-up question - the '-60 days' thing... this is not PHP syntax that I'm aware of; so it must be part of ModX... xPDO maybe? Do you have a link to where I can learn more about what you did there? Not having a lot of luck with Google on the subject.
                    • 22303 MODX Staff
                    • 10,725 Posts
                    Quote from: unsub777 at Feb 05, 2013, 05:07 PM
                    @openGeek:
                    Just a quick follow-up question - the '-60 days' thing... this is not PHP syntax that I'm aware of; so it must be part of ModX... xPDO maybe? Do you have a link to where I can learn more about what you did there? Not having a lot of luck with Google on the subject.
                    They are part of PHP. See http://www.php.net/manual/en/datetime.formats.relative.php for more information on relative date/time formats and all supported date/time formats at http://www.php.net/manual/en/datetime.formats.php.
                      • 36782
                      • 109 Posts
                      wow! well that's just great... I've been somehow unaware of an entire way of dealing with dates in PHP!! LOL

                      I don't suppose this is a recent addition? That might spare me some embarrassment smiley

                      Quote from: opengeek at Feb 05, 2013, 05:12 PM
                      Quote from: unsub777 at Feb 05, 2013, 05:07 PM
                      @openGeek:
                      Just a quick follow-up question - the '-60 days' thing... this is not PHP syntax that I'm aware of; so it must be part of ModX... xPDO maybe? Do you have a link to where I can learn more about what you did there? Not having a lot of luck with Google on the subject.
                      They are part of PHP. See http://www.php.net/manual/en/datetime.formats.relative.php for more information on relative date/time formats and all supported date/time formats at http://www.php.net/manual/en/datetime.formats.php.