I'm trying to convert a variable named $releasedate which contains the string 'May 31, 2011' to the string '2011-05-31 00:00:00' to insert into the database.

I have tried...

$pubdate = date('Y-m-d H:i:s',$releasedate);

...but it didn't work.

How do I do this?

Accepted Answer

You can use strtotime().

$pubdate = date('Y-m-d H:i:s', strtotime($releasedate)); // 2011-05-31 00:00:00


Written by alex
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki