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 NatarajanConnect With a Mentor LAMP 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
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
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
All Courses

From novice to tech pro — start learning today.