将String转换为Date值php

I have string value for date as "Wed, 25 Apr 2012 23:17:06 -0400"

I want to convert it into Date value

p.s : I'm using php 5.2.

try this

$str = "Wed, 25 Apr 2012 23:17:06 -0400";
$date = date("Y-m-d",strtotime($str));

do you mean:


$date = "Wed, 25 Apr 2012 23:17:06 -0400";
echo date("Y-m-d H:i:s", strtotime($date));
$date_val = 'Wed, 25 Apr 2012 23:17:06 -0400';
echo date('Y-m-d', strtotime($date_val)); 

You can change the date format whatever you want

Look at these:

http://www.php.net/manual/en/function.strtotime.php

http://www.php.net/manual/en/function.date.php

You could do something like date('Y-m-d' strtotime('Wed, 25 Apr 2012 23:17:06 -0400'));

I found this bellowing function and I hope it would be help full:

<?php
    $str = "Wed, 25 Apr 2012 23:17:06 -0400";
    $myDate = strtotime($str);
?>

Try this $dateSrc = "Wed, 25 Apr 2012 23:17:06 -0400"; $dateTime = new DateTime($dateSrc);