How to change date format in PHP Codeigniter?

How to change date format in PHP Codeigniter?

In this post we will give you information about How to change date format in PHP Codeigniter?. Hear we will give you detail about How to change date format in PHP Codeigniter?And how to use it also give you demo for it if it is necessary.

I would like to show you how to convert date format in php codeigniter 3 framework. we will change date format yyyy-mm-dd (Y-m-d) to dd-mm-yyyy (d-m-Y) with example.

we almost need to display date on any module or in detail page, so in this post i will give you simple example to change date formate in codeigniter. we will use core php function strtotime() and date() for convert date format.

i will share simple example to convert date format in codeigniter and also you can simply create helper function, so you can use same code repeatedly. So let’s see bellow easy example.

Simple Example:

$sampleDate = '2019-01-02';

$convertDate = date("d-m-Y", strtotime($sampleDate));




You can also create simple helper and repeatedly use it.

Helper Function:



function changeDateFormat($format = 'd-m-Y', $originalDate)


return date($format, strtotime($originalDate));



Use Helper Function:

Also see:How to get previous page url in codeigniter?


echo changeDateFormat('d-m-Y',$user->created_at)


I hope it can help you…

Hope this code and post will helped you for implement How to change date format in PHP Codeigniter?. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

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

30  +    =  39

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US