[thelist] PHP/MySQL Date Format Help

sbeam sbeam at syxyz.net
Wed Aug 4 09:37:42 CDT 2004


On Wednesday 04 August 2004 09:28 am, Rob Smith wrote:
> Can anyone offer a more cleaver way to reformat the YYYY-MM-DD into
> DD-MM-YYYY. Strangely enough I think I see the answer:
>
> $date = split("",$_POST["orderdate"]);
> $date = array_flip($date);
>
> Anything better?

You will take a performance hit by doing this in PHP. You could use the 
native mysql DATE_FORMAT() function
http://dev.mysql.com/doc/mysql/en/Date_and_time_functions.html
SELECT DATE_FORMAT(orderdate, "%d/%m/%Y") AS orderdate FROM table...

But if you really have an aversion to that then the PHP functions 
mktime() and date() are your friends.
list($y,$m,$d) = split('-', $row['orderdate']);
$str_date = date("%d/%m/%Y", mktime(0,0,0,$m,$d,$y);
don't forget to read the docs.

-- 

# S Beam - Web App Dev Servs
# http://www.onsetcorps.net/


More information about the thelist mailing list