Format date before save or show |
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?
You want to format it when you display it in your form.
PHP.net date You use the format. See the format options. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(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
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 What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
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 |
Welcome Guest, Not a member yet? Register Sign In |