Cannot Get Date format from input field |
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.
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"))); (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.
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
(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.
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 What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(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 (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. |
Welcome Guest, Not a member yet? Register Sign In |