How to Change Date Format in CodeIgniter

You can use strtotime() and date() of php as :

$join_dt = $row->start_date;
$newDate = date("d-m-Y", strtotime($join_dt));

$sampleDate = '2021-01-02';
$convertDate = date("d-m-Y", strtotime($sampleDate));

print_r($convertDate);

Results

01-02-2021

Helper Function:

if(!function_exists('setDtFormatLive'))
{
function setDtFormatLive($format = 'd-m-Y', $join_dt)
{
return date($format, strtotime($join_dt));
}
}

Use Helper Function:

<?php
echo setDtFormatLive('d-m-Y',$user->created_at)
?>

Example

$dob = "2021-03-08";
echo date("d-m-Y", strtotime($dob));
//Results date
08-03-2021

I hope you get an idea about Display date formats as DD MM YYYY in Codeigniter.


#codeigniter 

How to Change Date Format in CodeIgniter
1.00 GEEK