problem with date()
I am using the date() function to display a timestamp from my databse.
$date = date( 'F jS', $news_items['date']);
I 开发者_运维知识库know the $news_items['date'];
as they return in a YYYY-MM-DD 00:00:00 format.
But after the function call $date
dispays as December 31st for all values.
$date = date('F jS', strtotime($news_items['date']));
Try that :)
That's because date() wants a timestamp and not a string. You're better of with something like this;
$dt = date_create($news_items['date']);
$date = date_format($dt, 'F jS');
Or in the object oriented way;
$dt = new DateTime($news_items['date']);
$date = $dt->format('F jS');
The correct syntax for date function is given in PHP manual as:
string date ( string $format [, int $timestamp ] )
As you can see the second argument is expected to be an integer, but you are feeding the function with a string.
精彩评论