• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1231
  • Last Modified:

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.
0
gingera
Asked:
gingera
  • 2
  • 2
3 Solutions
 
RoonaanCommented:
$newDate = date('dd/mm/YYYY', strtotime('$x));
0
 
RoonaanCommented:
Or in a more string-manipulative way:

$newDate = implode('/', array_reverse(explode('-', $x)));
0
 
Deepika_RastogiCommented:
"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

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now