Reputation: 54989
I have an array with a key timestamp with the following content
"timestamp" => "2011-11-29 00:00:00"
When i try to change the format using this
date("F j, Y", $data['Visitor']['timestamp']);
i get the following error
A non well formed numeric value encountered
Upvotes: 0
Views: 761
Reputation: 219934
A newer way to do this as of PHP 5.2 is the DateTime class:
$datetime = new DateTime('2011-11-29 00:00:00');
echo $datetime->format('F j, Y');
Upvotes: 0
Reputation: 14951
The function requires the Unix Time which is numeric - and not a string formatted date.
As @Shakti Singh mentions you should use strtotime for that.
From the PHP docs on the timestamp parameter:
The optional timestamp parameter is an integer Unix timestamp that defaults to the current local time if a timestamp is not given. In other words, it defaults to the value of time().
Upvotes: 1
Reputation: 86476
You should be using the strtotime on the datetime data to convert it into Unix timestamp first.
date("F j, Y", strtotime($data['Visitor']['timestamp']));
Checkout the documentation of date it accept a Unix timestamp as a second parameter and you are passing a datetime value.
Upvotes: 6