Convert php date to mysql datetime format

Hi.
I have a date in the following format: dd/mm/YYYY.
I need to convert it to mysql dateTime. (Y-m-d H:i:s)

I have tried a couple of php date functions but i cant get them to work.

Can someone help me?

Keep in mind that MySQL comes with a NOW() function in it’s query structure for inserting the current dateTime.

Assuming your current input is not NOW() (or time()), strtotime() the date, and then feed the result into date() as the second parameter.

$date = date("Y-m-d H:i:s",strtotime($date))

Ok i tried that function and it works but now i have a problem.

Lets say i have the date 06/04/2010 in dd/mm/yyyy format. It should be converted to 2010-04-06 (yyyy-mm-dd) but it is converted into 2010-06-04 (yyyy-dd-mm).

Transform the data into the proper format. The date you give is assumed to be in mm/dd/yyyy format, because PHP is written in the US.

If you -know- for certain that your dates will always be in dd/mm/yyyy format, try transforming it this way:

$date = date("Y-m-d H:i:s",strtotime(str_replace('/','-',$date))) 

strtotime interprets x/y/z as mm/dd/yy[yy], and x-y-z as dd-mm-yyyy or yy-mm-dd, depending on whether z is 4 digits or 2.

Great.
It works now:D