I have tables with DATE or DATETIME fields where queries like:
Select dateField FROM table where <whatever>
return results, but when I fetch an association from the result set, the dateField in the row always produces 1969-12-31.
I know that the dateFields are correctly populating the tables because I can run queries from the MySQL command line and see that the date fields appear as expected, but when I run identical queries within a PHP script, the dates come back 1969-12-31. I have been getting around this situation until now by only using queries with dates in the where clause (where I have no problems), but I've finally run into a situation where I need to retrieve a value from a DATETIME field.
Here's a code snippet:
$query = "SELECT accessDate FROM requests WHERE orderid = '$orderid'";
$result = mysql_query( $query );
$numRes = mysql_num_rows( $result );
if ( $numRes > 0 )
{ $row = mysql_fetch_assoc( $result );
$accessDate = date( "Y-m-d", $row['accessDate'] );
echo "accessDate = $accessDate<br>";
}
Am I missing something?
Thanks, Mike
http://pnmx.com/