I have got a webpage that get some values from a mysql database, there's also a date value, I need to change it from y-m-d 2015-03-12 to d-m-y 12-03-2015 or better in for example Monday 12 March in italian if it's possibile how can I do?
This is what I tried:
$data= mysql_result($result,$i,"data");
$retrieved = '$data';
$date = DateTime::createFromFormat('Ymd', $retrieved);
echo $date->format('d/m/Y');
$data = $date;
The format in createFromFormat
must be Y-m-d
and the format in $date->format()
must be d-m-Y
you must change your formats like this:
<?php
$date = DateTime::createFromFormat('Y-m-d', '2015-03-12');
$date_out = $date->format('d-m-Y');
echo $date_out; //output 12-03-2015
echo "<br>
";
$date_out = $date->format('l d F');
echo $date_out; //output Thursday 12 March
?>
You can read more at: