moosey_man1988 Posted May 22, 2015 Share Posted May 22, 2015 Hi Everyone I need to change the way my dates are put into mysql and also displayed at the moment i have a javascript timepicker with validator that sets the date in the form as dd-mm-yy which displays as 25-05-2015 for example and i have it attached to POST like so : $dob = $_POST['dateofbirth']; and then finally once the form is entered it does this $sqlinsert = "INSERT INTO customers (prefix,Title,firstName,middleName,lastName,houseNo,Address1,postCode,ContactNo,DateOfBirth) VALUES ('$customer_prefix','$sex','$fname','$mname','$lname','$houseNo','$address1','$postcode','$contactno','$dob')"; but this puts the field in to the database wrong (e.g 22-05-2015) and I need to them go into the database like yyyy-mm-dd (e.g 2015-05-22) I was thinking of doing something like this? $originalDate = $dob;$newDate = date("Y-m-d", strtotime($originalDate)); I also need to pull this information back out of the database once again in format dd-mm-yy Thank you in advance for any help given. Quote Link to comment https://forums.phpfreaks.com/topic/296444-form-date/ Share on other sites More sharing options...
Barand Posted May 22, 2015 Share Posted May 22, 2015 You can reformat for display purposes in php using the date() function again or you can format in the sql using DATE_FORMAT() function EG SELECT DATE_FORMAT(dob, '%d-%m-%y') as dob FROM customers Quote Link to comment https://forums.phpfreaks.com/topic/296444-form-date/#findComment-1512431 Share on other sites More sharing options...
moosey_man1988 Posted May 22, 2015 Author Share Posted May 22, 2015 what is i wanted to select all the rows but display that with DATE_FORMAT? Quote Link to comment https://forums.phpfreaks.com/topic/296444-form-date/#findComment-1512471 Share on other sites More sharing options...
Barand Posted May 22, 2015 Share Posted May 22, 2015 And your problem with that is what? SELECT prefix ,Title ,firstName ,middleName ,lastName ,houseNo ,Address1 ,postCode ,ContactNo ,DATE_FORMAT(DateOfBirth, '%d-%m-%y) as dob FROM customers Quote Link to comment https://forums.phpfreaks.com/topic/296444-form-date/#findComment-1512474 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.