Another date compare question

15 posts by 4 authors in: Forums > CMS Builder
Last Post: March 4, 2010   (RSS)

By gkornbluth - February 28, 2010

Hi all,

I’m wrestling with another date compare issue.

My client has a series of Arts events listings on their site. Some events have Artists receptions and some do not.

If an event does has an artists reception, and during the week preceding that reception, they would like to be able to display those event listings to an “Upcoming Reception Reminders" section at the top of their web page.

I’m thinking that if I could compare the “current date + 7 days" with the” reception date” I could then set up an “if” statement something like:

If current date + 7 >= reception_date && current date < reception_date

... list event information...

Problem is, I’m stuck on how to compute the "current date + 7 days"

I've tried a number of variations on a previous post http://www.interactivetools.com/iforum/Products_C2/CMS_Builder_F35/gforum.cgi?post=77369 but have had no luck.

Any help appreciated.

Thanks,

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

Re: [Djulia] Another date compare question

By gkornbluth - February 28, 2010

Thanks Djulia,

I just had a look and tried to implement the code, but no matter what I try all I get is a blank page

I'm afraid with my limited knowledge I'm still really lost.

Jerry
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

Re: [gkornbluth] Another date compare question

By Dave - February 28, 2010

Hi Jerry,

Can you post your getRecords() code? Thanks!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Another date compare question

By gkornbluth - March 1, 2010

Thanks for getting into this one Dave,

I haven’t gotten very far at all with coding so the get records code is still just list($date_compare_testRecords, $date_compare_testMetaData) = getRecords(array(
'tableName' => 'date_compare_test',
));


I tried modifying the code below that I was using to compare dates in post #77369 but with very unhappy results.

<?php foreach ($general_meetingsRecords as $record): ?>

<?php
$eventUnixTime = strtotime( $record['date'] ); // seconds since 1970
$eventDateString = date("l, F jS", $eventUnixTime); // example format: Monday, June 1st
$currentUnixTime = time();
$currentDateString = date("l, F jS", $currentUnixTime);

$isEventToday = ($eventDateString == $currentDateString);
$isEventOver = !$isEventToday && ($eventUnixTime < $currentUnixTime);
$isFutureEvent = !$isEventOver && !$isEventToday;
?>

<?php if ($isEventOver): ?>
<br /> <span class="body-text-bold"><?php echo date("D, M jS, Y g:i a", strtotime($record['date'])) ?></span> <br />
<div align="left" class="body-text"><?php echo $record['content'] ?></div><hr align="left" color="#A29DB2" width="100" />
<?php endif; ?>

<?php endforeach ?>


Then Djulia suggested this other post, #67448, but when I insert the suggested code below into the page, no matter what I tried I ended up with a totally blank viewer and source. <?php
$days = (int) @$_REQUEST['days'];
if (!$days) { $days = 7 } // set default
$escapedDays = mysql_real_escape_string($days);
?>


I'd certainly appreciate you help,

Jerry
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

Re: [Dave] Another date compare question

By gkornbluth - March 1, 2010

Wow.

Thanks Dave,

I'll start playing around with it either later today or tomorrow and I'm sure that I'll have some questions as I get into it.

The code in post 67448 was yours, so I trust that you added the semicolon there too.

Best,

Jerry
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

Re: [gkornbluth] Another date compare question

By Dave - March 1, 2010

Oh, thanks! That's what happen when I write code in the forum and not in my editor! :)

I've updated the original post!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Another date compare question

By gkornbluth - March 3, 2010

Well Dave, you've done it again.

So far almost everything seems to work.

I needed to change the - to a + to get the logic to work correctly and change the single quotes to double quotes around the 23:59:59 or I got a blank page.

When I tested (at about 1:40pm local time) I found that the reception_date still does not show at all if it is equal to today's date. My local and MySQL times are both correct.

I won't be able to play with this any more today, but if you've got any ideas I'd like to hear them.

Here's what I used:

'where' => '(NOW() + INTERVAL 7 DAY) >= reception_date AND reception_date >= TIMESTAMP(CURDATE(), "23:59:59")',

The body code I used for a test was; <?php foreach ($date_compare_testRecords as $record): ?>
The Reception Date is <?php echo date("D, M jS, Y g:i a", strtotime($record['reception_date'])) ?>
<?php endforeach ?>




Thanks again for all your help,

Jerry
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

Re: [gkornbluth] Another date compare question

By Dave - March 4, 2010

Hi Jerry,

Heh, date math always makes my head hurt. Try this:
'where' => '(NOW() + INTERVAL 7 DAY) >= reception_date AND reception_date >= TIMESTAMP(CURDATE(), "00:00:00")',

Which I find easier to read if written like this:
'where' => 'TIMESTAMP(CURDATE(), "00:00:00") <= reception_date AND reception_date <= (NOW() + INTERVAL 7 DAY)',

Or in english (add this as a comment for the code above)
// If the reception date falls between 00:00 today -and- 7 days from now.

I think that's right. Can you give it a try and let me know if that works for you.
Dave Edis - Senior Developer
interactivetools.com