You are here: Re: [PHP] Date confusion « PHP « IT news, forums, messages
Re: [PHP] Date confusion

Posted by Rasmus Lerdorf on 10/21/81 11:22

Linda H wrote:
> Hi,
>
> I must admit I am surprised at the paucity of date and time functions in
> PHP.
>
> I have a date stored in a MySQL database in field of datatype date. PHP
> doesn't seem to have a function I can use to format it for print. I
> tried the following but regardless of the value in the date field, it
> displays as 'Wednesday December 31, 1969' (I know this is the day
> before the UNIX epoch.).
>
> echo '<p>'.date('l F j, Y',$start_date).'</p>';
>
> I tried casting the field to datetime, but it didn't pass the parser.
> Finally I did the following, which seems to work, but is awfully
> convoluted:
>
> echo '<p>Date: '.date('l F j, Y',strtotime($start_date).'</p>';
>
> The other thing I'm concerned about is that strtotime takes the locale
> into consideration. I don't want it adjusting the date - I just want it
> printed out.
>
> Is there a better way to do this?

If you have it in MySQL, there are a bunch of native MySQL functions to
format it on the select itself. See http://mysql.com/datetime

Or, if you want to manipulate it using PHP's functions, get MySQL to
return it to you as a UNIX timestamp.

-Rasmus

 

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

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