For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > September 2007 > date problems









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author date problems
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 ws 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
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com