![]() |
Format date before save or show - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: Format date before save or show (/showthread.php?tid=78491) |
Format date before save or show - pippuccio76 - 01-28-2021 im italian , in my form the date are in the dd-mm-Y format , how can i format in iso before save and update and format from db before show on page? RE: Format date before save or show - InsiteFX - 01-28-2021 You want to format it when you display it in your form. PHP.net date You use the format. See the format options. RE: Format date before save or show - pippuccio76 - 01-28-2021 (01-28-2021, 12:21 PM)InsiteFX Wrote: You want to format it when you display it in your form. but in the input form the date format is dd-mm-Y in db Y-mm-d RE: Format date before save or show - InsiteFX - 01-28-2021 Take the date and convert it to a Timestamp then MySQLi will be able to use it. You will also need to convert it back for the input if you use setVar. You can also use the object date format. Has better examples then date. PHP.net - DateTime::format RE: Format date before save or show - demyr - 01-28-2021 in the input? So, probably you are using a jquery ?? If yes, please check jqueryUI and the relevant part of it RE: Format date before save or show - Codinglander - 01-30-2021 Hi Pip I'm from germany and I had the same problem. My site supports two languages with different format of the date to input. In my model (CI4) I made two changes: First: PHP Code: protected $beforeInsert = ['getFormatedDate']; And second (the callback code for the $beforeInsert/$beforeUpdate): PHP Code: protected function getFormatedDate(array $data) The third thing I made is to check the input data via validation IN THE LANGUAGE THE USER SET. For this I created own rules for each language: PHP Code: public function format_date(string $str = null): bool I have in my database for each language ONE DateTimeFormat : Y-m-d H:i:s I hope, I could help yout to solve your problem ;) Greetinxx Kighlander |