I am storing the date of entry in mysql via TIMESTAMP and default value UNIX_TIMESTAMP, however when I bring it back it's 2011-08-16 11:43:52 and if I try to style it with
<?= date('F j, o', $a['time']) ?>
It just does the timestamp from zero, bringing back开发者_开发百科 December 31, 1970
Why? And how can I fix it?
Use
SELECT UNIX_TIMESTAMP(field)
When UNIX_TIMESTAMP()
is used on a TIMESTAMP
column, the function returns the internal timestamp value directly, with no implicit “string-to-Unix-timestamp” conversion.
Manual
A MySQL TIMSTAMP
column is stored as YYYY-MM-DD HH-MM-SS
, even if you input a UNIX_TIMESTAMP
it will still be stored in that format.
So what you can do is:
<?= date('F j, o', strtotime($a['time'])) ?>
Demo: http://codepad.org/jBLR2KpH
date()
takes a number and not a string. MySQL always returns your date as a string regardless of its internal representation. Try this:
<?php echo date("F j, o", strtotime($a['time']); ?>
精彩评论