| rDubya 2007-09-06, 6:59 pm |
| I'm having a problem with dates in php and mysql. I run a site that
promotes dated events and concerts and has the information for each
stored in a mysql database with the timestamp field.
Here is the function that checks the date of the event to ensure it is
between now and three w s from now (only events in this time period
are displayed on a page, with all events being displayed on another
page)
function check_date ($mysql_timestamp, $days) {
$timestamp = mktime(0, 0, 0, substr($mysql_timestamp, 4, 2),
substr($mysql_timestamp, 6, 2), substr($mysql_timestamp, 0, 4));
$event_day = date("z", $timestamp);
$event_year = date("Y", $timestamp);
$actual_day = date("z");
$actual_year = date("Y");
while ($event_year > $actual_year) {
$event_day = $event_day + 365;
$event_year--;
}
if (($event_day - $actual_day) <= $days && $event_day >=
$actual_day) { return TRUE; }
else { return FALSE; }
}
Then, to display the events that fill this criteria, there is this
code for the date:
function short_date ($mysql_timestamp) {
$stimestamp = mktime(0, 0, 0, substr($mysql_timestamp, 4, 2),
substr($mysql_timestamp, 6, 2), substr($mysql_timestamp, 0, 4));
$sformatted_date = date("D M j", $stimestamp);
return $sformatted_date;
}
My problem is that I have events dated for Sep 2007 and on, and yet
they all come up as being on Dec 7 to 9, 2006.. any ideas?
rDubya
|