We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31621
    • 23 Posts
    Hi,

    I have created a mini event manager by my self (A simple form to submit an event and using getPage and Rowboat, I fetch the list). Now, I would like to filter the events based on the Start Date (My table structure is: Title (Text), StartDate (Date), StartTime (Text), EndDate (Date), EndDate (Date), EndTime (Text), Location (Text) and Description (Text)).

    My date format is 4/15/2011 (m/d/y)

    My current call is as follows:
    [[!getPage:default=`There are no upcoming events.`?
    &element=`Rowboat`
    &table=`tableName`
    &sortBy=`startdate`
    &tpl=`eventsOnHome`
    &limit=`5`]]


    I would like to add a where clause to get only those events that are starting today or in the future. I don’t want to list the past events.

    I tried the following, by at this time the snippet sets the value to default.
    [[!getPage:default=`There are no upcoming events.`?
    &element=`Rowboat`
    &table=`tableName`
    &where=`{"startdate:>=", DATE_FORMAT(CURDATE(),'%e/%c/%Y')}`
    &sortBy=`startdate`
    &tpl=`eventsOnHome`
    &limit=`5`]]


    Can anybody help me resolve this, please.
      • 28215
      • 4,149 Posts
      Rowboat does not support literals like that. You should create another snippet, like say "getCurrentDate", and put it in the parameter:

      &where=`{"startdate:>=":"[[!getCurrentDate]]"}`
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 31621
        • 23 Posts
        Thanks. That worked for me.
          • 31621
          • 23 Posts
          I'm seeing a unique problem in this. In the below comparison the code assumes 06/15/2012 (%m/%d/%Y) to be a past date and does not display it in the list.

          My snippet call is:

          [[!getPage:default=`There are no upcoming events.`?
          &element=`Rowboat`
          &table=`TABLENAME`
          &where=`{"startdate:>=":"[[!getCurrentDate]]"}`
          &sortBy=`startdate`
          &cacheResults=`0`
          &totalVar=`rowboat.total`
          &tpl=`TPLNAME`
          &limit=`10`
          ]]

          where my startdate is a varchar date in the DB and getCurrentDate is as follows:
          <?php
          $rnStrFormat = '%m/%d/%Y';
          $rnStrToday = strftime($rnStrFormat);
          return $rnStrToday;

          What can I do to actually compare the two strings as dates to get the right output?
            • 31621
            • 23 Posts
            I was able to resolve the issue by simply changing the saved Date format and current date format to `yy/dd/mm`.

            In PHP strings are compared by their ordinal values of the characters from the {0} to the {strlen-1} one, thus comparing dates in the format `mm/dd/yy` would usually give incorrect results in some cases.