0

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

3 Answers 3

6

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.

DEMO

Sign up to request clarification or add additional context in comments.

Comments

1

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().

Comments

0

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');

See it in action

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.