[thelist] Date & time formatting

Max Schwanekamp lists at neptunewebworks.com
Fri Apr 14 03:30:07 CDT 2006

> From: Santilal Parbhu  
> I am sure that this problem has been encountered by many.  I 
> am using a PHP
> 4.0.4 to query a mysql database.  I want to be able to enter 
> times and dates in a format like say "12:00pm May 21", and I 
> want to be able to display it on my website in the same 
> format.  The yyyy-m-dd format is not very user friendly.

PHP's strtotime() may help you allow some more flexible date input formats.
For the dates in MySQL, I'd suggest you store them as unix timestamps, and
format them according to your (or your users' preferences).  So this way you
can format the user-entered date as a unix timestamp, store it that way, and
pull it back out as such, and use date() in PHP to format it.  (Or use
DATE_FORMAT() in your SELECT query). HTH.

Max Schwanekamp

More information about the thelist mailing list