You are here: Re: Converting MySQL dates « PHP Programming Language « IT news, forums, messages
Re: Converting MySQL dates

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация