tags:

views:

149

answers:

2

hi,

i need to convert a date in this format:

November 28, 2009

to a mysql date format:

2009-28-11

what's the best method to convert the date using php?>

thanks.

+4  A: 

Improvised from: http://www.bigroom.co.uk/blog/dates-in-php-and-mysql

$mysqldate = date( 'Y-m-d', strtotime( $phpdate ) );

// Example:
$phpdate = 'November 20, 2009';
$mysqldate = date( 'Y-m-d', strtotime( $phpdate ) );

echo $mysqldate;
// output: 2009-11-20
thephpdeveloper
Darn - beat me by just a few seconds. Good answer. ;)
antik
+1 for great answer and example code
Doug Neiner
cheers, thanks!
minimalpop
no problem at all!
thephpdeveloper
+2  A: 

I like to use strtotime and the date function as follows:

$mysql_date = date("Y-m-d", strtotime($source_date));

antik