If Statement based on Date

6 posts by 3 authors in: Forums > CMS Builder
Last Post: March 16, 2011   (RSS)

By zip222 - August 10, 2010

I have a section that uses the date field and I would like to divide up the listings on my page by items that are in the future and items that are in the past - based on the current date.

if the date of item is in the future, appear in list 1
If the date of item is in the past, appear in list 2

Here is the viewer code I am currently using, which only creates one list:

list($meetingsRecords, $meetingsMetaData) = getRecords(array(
'tableName' => 'meetings',
'loadUploads' => '0',
'allowSearch' => '0',
));


<table class="listings">
<tr>
<th>Upcoming Meetings</th>
</tr>
<?php foreach ($meetingsRecords as $record): ?>
<tr>
<td>
<a href="<?php echo $record['_link'] ?>"><?php echo date("l, F j, Y / g:i a", strtotime($record['meeting_date'])) ?></a>
</td>
</tr>
<?php endforeach ?>
</table>

Re: [zip222] If Statement based on Date

By zip222 - August 10, 2010

Nevermind, I figured it out. And in case anyone needs to know...

Just need to add this line:
'where' => "meeting_date > NOW()"
or this...
'where' => "meeting_date < NOW()"

Re: [zip222] If Statement based on Date

By zip222 - March 16, 2011

How do I modify this where statement to include records with a meeting_date that is either equal to or after today.

'where' => "meeting_date > NOW()"

basically this, which isn't working...
'where' => "meeting_date > NOW() OR meeting_date = NOW()"

Re: [zip222] If Statement based on Date

By Jason - March 16, 2011

Hi,

The MySQL NOW() statements give you the current time stamp to the second. If you're just interested in the day of the meeting (ie, the time of the meeting doesn't matter, you can try something like this:

First, get the current date formatted properly:

$currentDate = date("Y-m-d");

Then set up your WHERE clause like this:

'where' => "meeting_date LIKE '$currentDate%' ",

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] If Statement based on Date

By zip222 - March 16, 2011

so, not exactly...

What I am trying to do is generate a list of upcoming meetings and once a meeting date has passed I want it to no longer appear. But if there is a meeting happening today I do want it to appear. But at the moment they don't appear. I assume this is due to the fact that NOW() is based on the current time to the second and I am not inputting the time for my meetings.

I am looking for something like this...
'where' => "meeting_date > NOW() + 1 DAY",