Strawberry Strawberry - 3 months ago 6
MySQL Question

date() is showing December 1969

$sql = "SELECT * FROM news ORDER BY `news_id` DESC LIMIT 1";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($result);
$date = $row['time_posted'];
echo "<i> " .date("Y/m/d", $date) . "</i>: ";


I used timestamp in mysql.

Answer
date('Y/m/d', strtotime($date));

TIMESTAMP columns are not displayed as unix timestamps (anymore).

TIMESTAMP columns are displayed in the same format as DATETIME columns. In other words, the display width is fixed at 19 characters, and the format is 'YYYY-MM-DD HH:MM:SS'.

Comments