Specify date range in URL search

6 posts by 2 authors in: Forums > CMS Builder
Last Post: May 23, 2014   (RSS)

By nmsinc - May 22, 2014

What is the correct process for searching a specific date range in a URL search?

I need to list only records that the current date is more than 24 hours over the date of last update!

Thanks

nmsinc

nmsinc

By nmsinc - May 23, 2014

Thanks for the help - I have coded my $where statement as you suggested and I'm still having no luck. I'm sure it's just a punctuation error: Any ideas?

$where = "member_company = '".intval($CURRENT_USER['member_company_accounts'])."' and remove_record_from_listing = 0 and claim_status != 'Final' and acknowledgment != 'Accepted' and (NOW()+INTERVAL 2 DAY) >= updatedDate";

nmsinc

By gkornbluth - May 23, 2014

Hi nmsinc,

I think you're mixing up php and mysql. Unless I'm mistaken, NOW() is a mysql function and will only work in the list records 'where' =>

Here's a where statement that you can dissect for the syntax

<?php
    list($e_blast_events_noticeRecords, $e_blast_events_noticeMetaData) = getRecords(array(
    'tableName'   => 'e_blast_events_notice',
      'where' => '((NOW() + INTERVAL 7 DAY) >= opening_reception_date_and_start_time AND opening_reception_date_and_start_time >= TIMESTAMP(CURDATE(), "00:00:00")) OR ((NOW() + INTERVAL 7 DAY) >= event_start_date AND event_start_date >= TIMESTAMP(CURDATE(), "00:00:00")) AND apbc_event != 1',   
      
      'orderBy'=> 'neverRemove ASC, event_start_date ASC',
      ));  
      
    ?>

Hope that helps.

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By nmsinc - May 23, 2014

Hi Jerry,

I am using it in a list statement - please see below:

 $where = "member_company = '".intval($CURRENT_USER['member_company_accounts'])."' and remove_record_from_listing = 0 and status != 'Final' and acknowledgment != 'Accepted' and (NOW()+INTERVAL 2 DAY) >= updatedDate";
 
  list($submissionRecords, $submissionMetaData) = getRecords(array(
    'tableName'   => 'submission',
    'where'       => $where,
    'orderBy'     => 'num',
  ));

Thanks - nmsinc

nmsinc

By gkornbluth - May 23, 2014 - edited: May 23, 2014

I figured that, but I don't think you can use NOW() when defining the variable $where (that's a PHP thing not a MYSQL thing.)

You might think about using an if statement in your foreach loop and using something like the PHP function "time"

I'd try defining a few variables for current time, and time plus 2 days, and then compare those.

Something like:

<?php
$plus2days = time() +(2 * 24 * 60 * 60);
                   // 2 days; 24 hours; 60 mins; 60secs
                   ?>
   <?php // echo $plus2days?>      

<?php
$updatedDate = strtotime($record['updatedDate'])

           ?>
                  
   <?php // echo $updatedDate?>  

<?php if($plus2days >= $updatedDate ):?>

Show the data

<?php endif ?>

See if that approach works for you (no guarantees)

There are also some interesting ideas on the http://www.php.net/manual/en/function.date-add.php and other date function pages

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php