• Need help with Rowboat calls to filter based on Dates#

  • vishalashah Reply #1, 1 year, 1 month ago

    Reply
    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.


  • splittingred Reply #2, 1 year, 1 month ago

    Reply
    Rowboat does not support literals like that. You should create another snippet, like say "getCurrentDate", and put it in the parameter:

    &where=`{"startdate:>=":"[[!getCurrentDate]]"}`


  • vishalashah Reply #3, 1 year, 1 month ago

    Reply
    Thanks. That worked for me.


  • vishalashah Reply #4, 5 months, 1 week ago

    Reply
    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:>=":""}`
    &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?


  • vishalashah Reply #5, 5 months, 1 week ago

    Reply
    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.