I have this view
<?PHP
$no = 0;
foreach ($dt as $key => $row) {
$no++;
?>
<td style="text-align:center;"> <?=$row->TANGGAL_KADALUARSA;?> </td>
with result
21/11/2018 0:00:00
What I want is to change the format into
21 December 2018
Try this
$date = "21/11/2018 0:00:00";
echo date('d F Y', strtotime(str_replace('/', '-', $date)))
FYI: with this formation you can use this for saving in DB date which has
/
and MySQL won't throw an error with invalid date format.
you can convert that with this sample
$date=date_create("21-11-2018 0:00:00");
echo date_format($date,"d F y"); //it will echo 21 November 18
You can try this:
<?php
$str =$dt;
echo date('"d F Y"', strtotime($str));
?>
imho the best way here is the use of the DateTime::createFromFormat
function, try the following
<?php
$no = 0;
foreach ($dt as $key => $row) {
$objTanggalKadaluarsa = DateTime::createFromFormat('d/m/Y H:i:s', $row->TANGGAL_KADALUARSA);
$no++;
?>
<td style="text-align:center;"> <?=$objTanggalKadaluarsa->format('d F Y');?> </td>
try this (my format data is 2018-09-03 16:12:40)
$month = array("January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
);
echo substr($row->TANGGAL_KADALUARSA,8,2).' '.$month[substr($row->TANGGAL_KADALUARSA,5,2)-1].' '.(substr($row->TANGGAL_KADALUARSA,0,4)).' | '.substr($row->TANGGAL_KADALUARSA,-8);