Strawberry
Strawberry

Reputation: 67928

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.

Upvotes: 1

Views: 4798

Answers (2)

Michael Mrozek
Michael Mrozek

Reputation: 175595

The UNIX epoch was at January 1, 1970 at exactly midnight UTC. If you live in a timezone behind UTC, timestamp 0 will show up sometime in the evening of December 31, 1969. ($date is most likely 0)

Upvotes: 0

timdev
timdev

Reputation: 62904

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'.

Upvotes: 4

Related Questions