How to change date format in PHP Codeigniter?
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.
$sampleDate = '2019-01-02';
$convertDate = date("d-m-Y", strtotime($sampleDate));
You can also create simple helper and repeatedly use it.
function changeDateFormat($format = 'd-m-Y', $originalDate)
return date($format, strtotime($originalDate));
Use Helper Function:
I hope it can help you...
We are Recommending you
- JQuery Ajax Request Example in Codeigniter
- Codeigniter 3 resize image and create thumbnail example
- How to get current controller or method name in Codeigniter ?
- Codeigniter - Dynamic dependent dropdown using jquery ajax Example
- Codeigniter 3 - CRUD(Create, Read, Update and Delete) using JQuery Ajax, Bootstrap, Models and MySQL
- Codeigniter 3 - select2 ajax autocomplete from database example with demo
- How to get current url with query string in codeigniter?
- Codeigniter - How to get current url in controller or view ?
- How to get Ip Address in Codeigniter?