We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16462
    • 3 Posts
    I am a newcomer to MODX and am slowly converting my old websites. I am starting to understand xPDO objects and have used the following snippet to place events onto the correct resource. The issue I have is with the line starting where(array...

    I want to choose where the event date (ev_edate) is equal to or later than today's date. (I always seem to have a problem with date formats and have spend some time over the last two weeks on this piece of code, without success). The row 'ev_edate' in my table is datetime and thinks work perfectly with a specific date in the line. Help would be greatly appreciated as I have a number of other pages that require date formatting.

    I have Bob's Official Guide and have read many items in the Documentation and Forums without success.

    ($path = MODX_CORE_PATH . 'components/kfbev/';
    $result = $modx->addPackage('kfbev',$path .
    'model/','kfb_');

    $evsort = 'ev_edate';
    $s = $modx->newQuery('kfbev');
    $s->sortby($evsort,'ASC');
    $s->where(array( 'ev_edate:>=' =>'2014-01-01 10:13:03'));

    $kfbevents = $modx->getCollection('kfbev',$s);
    foreach($kfbevents as $kfbevent) {
    $fields = $kfbevent->toArray();
    $output .= $modx->getChunk('KFBEShowEvent', $fields);
    }
    return $output;
      • 4172
      • 5,888 Posts
      if ev_edate is of type datetime, this should work.

      What do you get with this query?
      What do you get, when you add
      $c->prepare();echo $c->toSql();
      

      before the getCollection - line?
      What is your xpdo-schema for your kfbev - object?
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 16462
        • 3 Posts
        Perhaps I didn't make myself clear. The snippet does work perfectly but what I am trying to do is replace the absolute date in the line below with the automatic current date.

        So instead of this:
        $s->where(array( 'ev_edate:>=' =>'2014-01-01 10:13:03'));

        I want something like
        $s->where(array( 'ev_edate:>=' =>'current date and time now perhaps using date()'));

        It's the format of the date() in this line that is giving me grief.

          • 4172
          • 5,888 Posts
          try:

          $s->where(array( 'ev_edate:>=' =>strftime('%Y-%m-%d %H:%M:%S')));


          or starting at 00:00

          $s->where(array( 'ev_edate:>=' =>strftime('%Y-%m-%d 00:00:00')));
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 16462
            • 3 Posts
            Thank you Bruno.

            That fixed the issue here. FYI Also looking at MIGX and bloX for my sites. No doubt I'll be back with issues later!