1

Ok i have this in my mysql database in a datetime field

2011-12-30 14:07:46

i need using php to use this format

December 30, 2011, 2:07 pm

so i used this

date("F j, Y, g:i a", $system['date_added']);

but the outcome was this error

A non well formed numeric value encountered in quote.php on line 56

and this outcome

December 31, 1969, 4:33 pm

I know there is

print_r(date_parse($system['date_added']));

but i get an array....any ideas on an easy way to address this

1
  • 1
    SO is so popular that people dont go to forum, irc, list or even google Commented Dec 30, 2011 at 20:23

4 Answers 4

3

The second param of the date should be the unix timestamp, which you can get using strtotime which gets string representation of a date and converts it to unix timestamp:

date("F j, Y, g:i a", strtotime($system['date_added']));
Sign up to request clarification or add additional context in comments.

2 Comments

correct answer, but how should anyone learn from this without even a tiny piece of explanation?
strtotime() converts an english formatted time string to an UNIX-Timestamp. That you can convert to any time format you want.
3

You can use strtotime.

date("F j, Y, g:i a", strtotime($system['date_added']));

Comments

2

The date()'s second argument is a UNIX timestamp, you're giving it 2011-12-30 14:07:46 which is not.

There are two ways to handle this. Either one will work.

  • Pull out the date as a UNIX timestamp.

    SELECT UNIX_TIMESTAMP(`field`) FROM ...
    
  • Parse the date using strtotime().

    $timestamp = strtotime($system['date_added']);
    date("F j, Y, g:i a", $timestamp);
    

Comments

0

wrap your db-date with strtotime()

http://php.net/manual/en/function.strtotime.php

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.