How to (Easily) Change Date Format in codeigniter?

Today, We want to share with you date format codeigniter.In this post we will show you get only date from datetime in codeigniter, hear for time ago in codeigniter we will give you demo and example for implement.In this post, we will learn about Date Formats In PHP Codeigniter with an example.

How to change date format in PHP 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:

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.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment