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
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']));
You can use strtotime
.
date("F j, Y, g:i a", strtotime($system['date_added']));
wrap your db-date with strtotime()
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);