PHP Convert dates

Can someone help with the syntax to convert dates such as 06/09/2011 to 2011-09-06 please?
PeterErhardAsked:
Who is Participating?
 
Loganathan NatarajanLAMP DeveloperCommented:
Simple way with explode() function


<?php

$strng = "06/09/2011";
$parse = explode("/", $strng);

$modified_date = $parse[2]."-".$parse[1]."-".$parse[0];

echo $modified_date;



?>

Open in new window

0
 
Cornelia YoderArtistCommented:
http://us2.php.net/manual/en/function.strtotime.php

will convert the string to a unix timestamp

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

will convert a unix timestamp to whatever date format you want.
0
 
Cornelia YoderArtistCommented:
$olddate = "06/09/2011";

$unixtimestamp = strtotime($olddate);

$newdate = date("Y-m-d",$unixtimestamp);
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
Loganathan NatarajanLAMP DeveloperCommented:
Try this

echo date('Y-m-d', strtotime($strng))
0
 
OmniUnlimitedCommented:

<?php

$date = date_create_from_format('d/m/Y', '06/09/2011');
echo date_format($date, 'Y-m-d');

?>

Open in new window

0
 
Cornelia YoderArtistCommented:
Well, since you neglected to at least thank others who tried to help you, ....

You're welcome, anyway.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.