Edvin Cekani
Edvin Cekani
Software Developer
Edvin Cekani

Blog

How to change date format in PHP Codeigniter?

How to change date format in PHP Codeigniter?

We will change date format yyyy-mm-dd (Y-m-d) to dd-mm-yyyy (d-m-Y) with example.

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

You can also create simple helper and repeatedly use it.

Helper Function:

if(!function_exists('changeDateFormat')) {

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

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

}

Use Helper Function:

<?php echo changeDateFormat('d-m-Y',$user['create_date']); ?

Free Web Hosting