I extracted a date out of a MySQL database:
echo $nextup['date']
which is echoed as an DATETIME:
2014-03-19 15:21:42
Now, I'd like to convert/cast this to a readable form:
19 March 2014 15:21:42
but I couldn't find how. I've read the date/time manual for PHP but it doesn't say how to convert.
Thanks in advance!
Try strtotime
and date
combination:
function translate_names($eng) {
$names = array (
'Januari' => 'January',
'Februari' => 'February',
'Maart' => 'March',
'April' => 'April',
'Mei' => 'May',
'Juni' => 'June',
'Juli' => 'July',
'Augustus' => 'August',
'September' => 'September',
'Oktober' => 'October',
'November' => 'November',
'December' => 'December',
);
return array_search($eng, $names);
}
$date = $nextup['date'];
$month = addcslashes(translate_names(date('F', strtotime($date))), 'a..zA..Z');
$string = "d $month Y H:i:s";
echo date($string, strtotime($date));
echo date('d D Y H:i:s' , strtotime($nextup['date']));
This should work.
aksu was first, but for completeness, you could also do…
$dateTime = new DateTime($nextup['date']);
echo $dateTime->format("d F Y H:i:s");
$date = new DateTime("now");
echo date_format($date, "d F Y h:i:s");