tags:

views:

69

answers:

3

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.

+6  A: 
$date = date('F jS', strtotime($news_items['date']));

Try that :)

inkedmn
+2  A: 

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');
Björn
+2  A: 

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.

Majid