1

I am receiving the error: A non well formed numeric value encountered

Here is my code:

<?php

$timestamp= '2013-01-20 18:20:20';

$datetime= date('F j, Y', $timestamp);

    echo $datetime;

?>

This returns January 1, 1970 Which isn't right. What am I doing wrong? BTW: All of my $timestamp variables will be in that format. I am using datetime in my MySQL database table.

Thanks

1
  • Just for clarification also, there are several "timestamps" (each database uses their own). php uses the "unix timestamp" which represents the number of seconds since "January 1, 1970 00:00:00 UTC". The timestamp the OP is using is not a valid "unix timestamp" and so date() thinks the "unix timestamp" passed in is 0 meaning 0 seconds since "Jan 1 1970". en.wikipedia.org/wiki/Unix_time Commented Jan 24, 2013 at 20:53

2 Answers 2

4

the date function takes a timestamp which is an int you need to call it using

date('F j, Y', time());

or

$timestamp= '2013-01-20 18:20:20';
date('F j, Y', strtotime($timestamp));

see http://php.net/manual/en/function.date.php for info on how to use the date function

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

Comments

3

'2013-01-20 18:20:20' is not a timestamp . You have to convert it to timestamp. You can use strtotime function to do this.

$timestamp= strtotime('2013-01-20 18:20:20');

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.