hubertj Posted March 30, 2012 Share Posted March 30, 2012 Hi Guys...i have this problem... I have this page where user can type in their date of birth...I would like to convert the date of birth input by the user to the DATA format which is defined by phpmyadmin (YYY-MM-DD) so that i can put into the database... My main objective of this is to calculate age... I have this form to allow use to type date of birth: <label for="dob">D.O.B.: </label> <input type="text" name="dob" id="dob" class="regfields"/> This is to store the input to a variable: $adddob = $_POST['dob']; and finally this query to insert all the input into the database: $query = "insert into emp (FNAME, LNAME, CDSID, PAYNO, MAIL , TELNO , DOB , BRANCH , LICNO , CLASS , VFROM , VTO , EID , PASS , PIN) values ('$addfname','$addlname','$addcdsid','$addpayno','$addmail','$addtelno','$adddob','$addbranch','$addlicno','$addclass','$addvfrom','$addvto','$addeid','$addpassword','$addpin')"; Thanks in advance...If this is possible then I will set my dob column to the DATA format... Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 30, 2012 Share Posted March 30, 2012 Typically you want to provide the user a format that they are to follow when entering the date and/or provide a popup calendar. So, what format do you expect the user to enter the date? As long as you use a standard'ish' format you can use strtotime() to convert to a format that can be used in PHP then translated into a proper format for the database. $adddob = strtotime($_POST['dob']); $sql_date = date('Y-m-d', $adddob); Of course you definitely want to add some validation to this. Quote Link to comment Share on other sites More sharing options...
samshel Posted March 30, 2012 Share Posted March 30, 2012 Adding popup calendar or 3 drop downs with day, month, year is the best way to go, avoiding any input errors or confusing the user to how to input the date. Quote Link to comment 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.