Reputation: 702
Am saving to a mysql table using:
$query = mysql_query("INSERT INTO test SET postit='$postit',postdate=NOW()");
I'm then trying to display it using:
echo "<li>" . date("D, d M y H:i:s O",$row['timestamp']) . " - " . $row['postit'] . "</li>";
It's saving the correct time in the database, however it renders:
Thu, 01 Jan 70 01:00:00 +0100
Anyone point out the stupidity?
Upvotes: 3
Views: 7757
Reputation: 72672
I always like to use this function for that:
function parse_sql_timestamp($timestamp, $format = 'd-m-Y')
{
$date = new DateTime($timestamp);
return $date->format($format);
}
This way we can even go beyond 2038 ;)
Upvotes: 2
Reputation: 12059
The PHP date() function uses a Unix timestamp as the second variable in the function. What you are passing to the function is a MySQL time stamp. Try using:
echo date("D, d M y H:i:s O",strtotime($row['timestamp']));
Upvotes: 10