Compare dates
17 posts by 4 authors in: Forums > CMS Builder
Last Post: January 27, 2010 (RSS)
Do you think it could it have something to do with the way I'm formatting the dates when I define
$eventDateString = date("l, F jS", $eventUnixTime);
and
$currentDateString = date("l, F jS", $currentUnixTime);
?
Thanks,
Jerry
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Re: [gkornbluth] Compare dates
By Chris - January 13, 2010 - edited: January 13, 2010
You're having a problem in which a meeting for today is showing up in your "past meetings" list. I wonder if this could this be a timezone issue -- is your "today" the same as your server's "today"?
Let's make sure all the variables are what we expect them to be; add the code in red to your bottom list (you can comment out the top list for now to make your output easier to follow if you want):
<?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;
?>
Testing event:
<ul>
<li>Event date = <?php echo $eventDateString ?></li>
<li>Current date = <?php echo $currentDateString ?></li>
<li>$isEventToday = <?php echo $isEventToday ? "true" : "false" ?></li>
<li>$isEventOver = <?php echo $isEventOver ? "true" : "false" ?></li>
<li>$isFutureEvent = <?php echo $isFutureEvent ? "true" : "false" ?></li>
</ul>
<?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 ?>
If you have an event which occurs on the current day, it should show the same date as the current day and "$isEventToday = true".
Please post your findings and we'll get to the bottom of this.
Chris
Thanks for this.
I'm not ignoring you but I need to finish some stuff before I can get back to it.
I'll let you know what I find.
Jerry
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Re: [gkornbluth] Compare dates
By Chris - January 14, 2010
No worries. Take your time. I'm subscribed to the thread, so I'll see when you respond, whether it's in 2 days or 2 months. :)
Chris
By gkornbluth - January 26, 2010 - edited: January 26, 2010
Well I finally was able to return to this issue, and indications point the fact that both the test for “isFutureEvent” and the test for “isEventOver” excluded a match for “isEventToday”.
I got around this by creating another test for “isEventToday” and display that group at the top of the “meetings” viewer as “Today’s Events”.
I also noticed that my “server” time is 5 hours later than my “local” time.
When I inserted the test code, added an extended currentUnixTime showing hours, minutes and seconds and tested the page, everything worked as expected, the test results made sense, and items were displayed in the correct areas on the page. Unless I'm wrong, it appears that the currentUnixTime is dependent on local time not server time.
This also seems to be related to the issue presented in Show_date/time_and_time_zones._P77048
Best,
Jerry
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Re: [gkornbluth] Compare dates
By Dave - January 27, 2010
Is your timezone set correctly under: Admin > General > Regional Settings?
Date math is notoriously difficult, for this and many other reasons.
If this is still an issue, and the timezone is set correctly then we'll have to go line by line and figure out which line is giving us the wrong date.
interactivetools.com
Re: [Dave] Compare dates
As I mentioned in my last post, everything seems to be working as expected.
Thank you all for your help.
Jerry
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php