Cannot Get Date format from input field - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Cannot Get Date format from input field (/showthread.php?tid=70982) |
Cannot Get Date format from input field - sanjaya - 06-24-2018 I am trying insert birth day from codeigniter form to mysql database as mysql date format, But i am getting like this format "06/27/2018". My model as below PHP Code: After that I try to get birth day to reminder. But its not work with this date format. I am using bootstrap datetimepicker. RE: Cannot Get Date format from input field - Pertti - 06-25-2018 Browsers use different date format than MySQL servers. You have to convert it from one format to another before you add it to DB, but there are few helpful PHP functions that might solve this fairly easily: PHP Code: $birth_day = date('Y-m-d', strtotime($this->input->post("b_day"))); RE: Cannot Get Date format from input field - sanjaya - 06-25-2018 (06-25-2018, 12:33 AM)Pertti Wrote: Browsers use different date format than MySQL servers. You have to convert it from one format to another before you add it to DB, but there are few helpful PHP functions that might solve this fairly easily: Thanks Pertti, It's work. RE: Cannot Get Date format from input field - Pertti - 06-25-2018 You probably need to add some checks, because if b_day wasn't provided, strtotime will return false, and date in return will use it as 0 - which will give you dates in year 1970, but glad it worked RE: Cannot Get Date format from input field - sanjaya - 06-25-2018 (06-25-2018, 02:31 AM)Pertti Wrote: You probably need to add some checks, because if b_day wasn't provided, strtotime will return false, and date in return will use it as 0 - which will give you dates in year 1970, but glad it worked I am new to web development. Can you help me to resolve this error. RE: Cannot Get Date format from input field - InsiteFX - 06-25-2018 You really should read up on the DateTime Class etc; On PHP.NET Here is one example that will help you to check the datetime. date_parse RE: Cannot Get Date format from input field - sanjaya - 06-25-2018 (06-25-2018, 03:37 AM)InsiteFX Wrote: You really should read up on the DateTime Class etc; On PHP.NET Now I am getting below error. "Array to string conversion" This is my code. PHP Code: value="<?php RE: Cannot Get Date format from input field - Pertti - 06-25-2018 (06-25-2018, 04:42 AM)sanjaya Wrote: "Array to string conversion" Did you read the documentation? date_parse will return array of date values broken down into array, while date + strtotime will give you a string in format you specify. We have pointed you to solution for original issue, which was reformatting dates that come in from browser and need to go in DB in different format. |