Listing by specific date on Detail List Page

6 posts by 3 authors in: Forums > CMS Builder
Last Post: August 5, 2013   (RSS)

To list only today's records you might try this suggestion from Dave Edis:

'where' => "YEAR(date) = YEAR(NOW()) AND DAYOFYEAR(date) = DAYOFYEAR(NOW())",


If that doesn't help, there are some pretty detailed recipes in my CMSB Cookbook http://www.thecmsbcookbook.com that deal with comparing dates, showing dates within a range and other ideas for working with dates.

Hope this 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

Hi,

Just an idea...

If you were looking for this weeks event reminders you might be able to define  some variables and then use if statements to separate the results...

$eventdate =    strtotime($record['date']);
$dateplus0 = strtotime(date('Y-m-d', strtotime("+ 0 day")));
$dateplus1 = strtotime(date('Y-m-d', strtotime("+ 1 day")));
$dateplus2 = strtotime(date('Y-m-d', strtotime("+ 2 day")));
etc...

Then compare the variables something like:

if ($dateplus0 == $event date)

show today's events

elseif ($dateplus1 == $event date)

Show tomorrows events

elseif ($dateplus2 == $event date)

Show  events 2 days from now

Etc.

best,

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 - August 3, 2013

Hi Jerry,

Sorry if I have confused you. All I need to do is filter the list results by the field "date". The funny thing is; I cannot filter by any of the fields. Any field filter request I make returns all records!

nmsinc

This returned only today's events in my test and returned the correct values for the variables

<?php
  /* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */

  // load viewer library
  $libraryPath = 'cmsAdmin/lib/viewer_functions.php';
  $dirsToCheck = array('/hsphere/local/home/apbcweb/artistsofpalmbeachcounty.org/','','../','../../','../../../');
  foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
  if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

  // load records
  list($nmsinc_testRecords, $nmsinc_testMetaData) = getRecords(array(
    'tableName'   => 'nmsinc_test',
    'where' => "YEAR(date) = YEAR(NOW()) AND DAYOFYEAR(date) = DAYOFYEAR(NOW())", // limit to today's events
  ));

?>

 <h1>nmsinc test - List Page Viewer</h1>
    <?php foreach ($nmsinc_testRecords as $record): ?>
    <?PHP
$eventdate =    strtotime($record['date']);
$dateplus0 = strtotime(date('Y-m-d', strtotime("+ 0 day")));
$dateplus1 = strtotime(date('Y-m-d', strtotime("+ 1 day")));
$dateplus2 = strtotime(date('Y-m-d', strtotime("+ 2 day")));

?>

      Record Number: <?php echo $record['num'] ?><br/>
      Date: <?php echo date("D, M jS, Y g:i:s a", strtotime($record['date'])) ?><br/>
      <!-- For date formatting codes see: http://www.php.net/date -->
      title: <?php echo $record['title'] ?><br/>
      event date: <?php echo $eventdate ?><br/>
      event date +0: <?php echo $dateplus0 ?><br/>
      event date +1: <?php echo $dateplus1 ?><br/>
      _link : <a href="<?php echo $record['_link'] ?>"><?php echo $record['_link'] ?></a><br/>

      <hr/>
    <?php endforeach ?>

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

Hi Jerry and nmsinc,

Did you end up resolving this post? Were you trying to filter items in a section based on date?

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com