Click to See Complete Forum and Search --> : PHP date conversion newbie


prachu
11-26-2007, 02:41 PM
Hi All

I would like to convert dates from dd-mmm-yyyy format to the mysql yyyy-mm-dd format. How does one do this in php?Thanks a lot

NogDog
11-26-2007, 04:07 PM
One way:

$yyyymmdd = implode('-', array_reverse(explode('-', $date)));

masterkey
11-26-2007, 11:33 PM
The more general way to do this is, if you want to get from format A to format B is date(format B, strtotime(var in format A))

Mysql format date (http://php-date.com/#mysql) for php's date function is 'Y-m-d', so

$output = date('Y-m-d', strtotime($input));

where $input can actually be the date in virtually any format