I am trying to grab dates stored as DATETIME in my mysql db. The dates are correct in the database. When I check the timestamp in the db and in the values of $eventTimeTS and $startDateTS, they match. (i believe)
After I try to use the date() function to format the dates,
I get the wrong dates. The dates I get for startDate,endDate, and eventDate respectively are:
November 12, 2002 12:00 am
December 31, 1969 6:59 pm
December 31, 1969 7:00 pm
The dates are the same no matter what the actual date is in the db. Even though the dates in the db change from id to id, those above dates always show up. This is the code im using:
$Query = "SELECT unix_timestamp(eventTime) as eventTime";
$Query .= ", unix_timestamp(created) as created from tickets";
$dbResult = mysql_query($Query, $dbLink) or die("query failed".mysql_error());
$row = mysql_fetch_array($dbResult, MYSQL_BOTH);
$eventTimeTS = $row['eventTime'];
$startDateTS = $row['created'];
// correct so far
$endDate = mktime(date('g',$eventTimeTS),
date('i',$eventTimeTS),
date('a',$eventTimeTS),
date('m',$eventTimeTS),
date('d',$eventTimeTS)-1,
date('Y',$eventTimeTS));
$endDate = date('F d, Y g:i a', $endDate);
$eventTime = date('F d, Y g:i a', $eventTimeTS);
$startDate = date("F d, Y g:i a", $startDateTS);
Been working on this for a bit trying to get the dates using date_format() in mysql select, but that didnt work either, I get the same wrong dates. I dont get it? Anyone have any ideas?