tags:

views:

46

answers:

4

the date stringe is Apr 30, 2010

I want to parse the string into 2010-04-30 using php, how can I achieve this?

Thanks!!

+5  A: 

Try http://php.net/manual/en/function.strtotime.php to convert to a timestamp and then http://www.php.net/manual/en/function.date.php to get it in your own format.

zaf
A: 

as zaf said you have to pass by timestamp.

aleo
+3  A: 

Either with the DateTime API (requires PHP 5.3+):

$dateTime = DateTime::createFromFormat('F d, Y', 'Apr 30, 2010');
echo $dateTime->format('Y-m-d');

or the same in procedural style (requires PHP 5.3+):

$dateTime = date_create_from_format('F d, Y', 'Apr 30, 2010');
echo date_format($dateTime, 'Y-m-d');

or classic (requires PHP4+):

$dateTime = strtotime('Apr 30, 2010');
echo date('Y-m-d', $dateTime);
Gordon
A: 

php.net/strtotime

Harold1983-