w3resource logo
php Programming Exercies

PHP Date Exercises : Convert a date from yyyy-mm-dd to dd-mm-yyyy

PHP date: Exercise-5 with Solution

Write a PHP script to convert a date from yyyy-mm-dd to dd-mm-yyyy.

Sample date : 2012-09-12

Sample Solution:

PHP Code:

<?php
$odate = "2012-09-12";
$newDate = date("d-m-Y", strtotime($odate));
echo $newDate."\n";
?>

Sample Output:

12-09-2012

Flowchart :

Flowchart: Convert a date from yyyy-mm-dd to dd-mm-yyyy

PHP Code Editor:

<?php
$odate = "2012-09-12";
$newDate = date("d-m-Y", strtotime($odate));
echo $newDate."\n";
?>

Improve this sample solution and post your code through Disqus.