|
Posted by Chris Hope on 09/01/06 04:09
Tgone wrote:
> I need to convert a MySQL date "2007-03-08", into "March 8th, 2007".
> Normally I would use MySQL to accomplish this task but I have to use
> PHP.
>
> Here's my code:
>
> echo date("F jS, Y", $row['date']);
>
> But this returns "December 31st, 1969". I'm not sure what's going on
> here. Any ideas?
date() expects a unix timestamp as the parameter and you're passing it a
string. Convert it to a unix timestamp either in the sql or using php's
strotime() function like so:
echo date("F jS, Y", strtotime($row['date']));
Note that when using unix timestamps for date and time functions you
have a limited date range from 1970 to 2038. Ideally it's best to do it
in the database query rather than in PHP.
In MySQL you would use the DATE_FORMAT() function which can be found on
the following page of the MySQL manual:
http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html
--
Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com
[Back to original message]
|