PHP MYSQL: How to convert yyyy-mm-dd to dd/mm/yyyy?

Hello,

How do I convert $x from "yyyy-mm-dd" to "dd/mm/yyyy" in a PHP script?

Thanks.
gingeraAsked:
Who is Participating?
 
RoonaanConnect With a Mentor Commented:
$newDate = date('dd/mm/YYYY', strtotime('$x));
0
 
RoonaanConnect With a Mentor Commented:
Or in a more string-manipulative way:

$newDate = implode('/', array_reverse(explode('-', $x)));
0
 
Deepika_RastogiConnect With a Mentor Commented:
"yyyy-mm-dd" to "dd/mm/yyyy"
Try this ($original is the date in the "yyyy-mm-dd" format) :

function convertdate($original)
{
$year = substr($original,0,4);
$month =substr($orginal,5,2);
$day = substr($original,8,2);

$newdate = "$day/$month/$year";

return $newdate;
}
0
 
gingeraAuthor Commented:
THANKS!
0
 
gingeraAuthor Commented:
I have to clarify Roonaan's 1st suggestion should read:

$newDate = date('d/m/Y', strtotime('$x));

not

$newDate = date('dd/mm/YYYY', strtotime('$x));
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.