Convert dd/mm/yyyy to yyyy-mm-dd in codeigniter
Convert dd/mm/yyyy to yyyy-mm-dd in codeigniter
In this session, we will try our hand at solving the "Convert dd/mm/yyyy to yyyy-mm-dd in codeigniter".
To convert the date-time format PHP provides strtotime() and date() functions. We can convert date format from dd/mm/yyyy to yyyy-mm-dd in codeigniter using str_replace() method before date() and strtotime() methods.-
Change date format from dd/mm/yyyy to yyyy-mm-dd in PHP
<?php $orgDate = "11/05/2021"; // (DD/MM/YYYY) $date = str_replace('/', '-', $orgDate); $newDate = date("Y-m-d", strtotime($date)); echo "New date format is: ".$newDate. " (YYYY-MM-DD)"; ?>
Suppose we have a date 11/05/2021 in DD/MM/YYYY format separated by dash (/) sign. We want to convert this to 2021-05-11 (YYYY-MM-DD) format, which will be separated by the slash (-). We can change the date format using strtotime() method after str_replace() method on a given date which is used to replace (/) with (-).
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: CodeIgniter
- Codeigniter 4 call model function from controller
- How to load a view in CodeIgniter?
- Get last executed query in codeigniter
- Update an existing table record with +1 in CodeIgniter
- Call to undefined function CodeIgniter\locale_set_default()
- Unable to set session in codeigniter
- How to call helper function in Codeigniter view
- Default htaccess file code Codeigniter
- How to get field names of table in Codeigniter
- No input file specified Codeigniter
- How to move from one view to another in Codeigniter
- How to create custom helper in codeigniter 4
- How to select all checkbox in Codeigniter
- Get the version codeIgniter