Converting MySQL dates

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

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

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?

Re: Converting MySQL dates

Tgone wrote:

Quoted text here. Click to load it

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:

Chris Hope | |

Re: Converting MySQL dates

Chris Hope wrote:
Quoted text here. Click to load it

Thanks! I tried the code and it works. I appreciate your advice.

Re: Converting MySQL dates

*** Tgone escribió/wrote (31 Aug 2006 20:59:26 -0700):
Quoted text here. Click to load it

In order that this code works as expected, you need that your query looks
like this:


-+ - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web:
+- Mi web de humor con rayos UVA:

Site Timeline