1

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.

6 Answers 6

2

try this

$str = "Wed, 25 Apr 2012 23:17:06 -0400";
$date = date("Y-m-d",strtotime($str));
Sign up to request clarification or add additional context in comments.

Comments

1

do you mean:


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

Comments

1
$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

Comments

0

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'));

Comments

0

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);
?>

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.