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:

<?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.
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.

Read Also:  How to get only date from datetime in CodeIgniter? - how to get current date in codeigniter?

About Pakainfo

I am Jaydeep Gondaliya, a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Pakainfo →

Leave a Reply

Your email address will not be published. Required fields are marked *