Jump to content

Date and age problem


hubertj

Recommended Posts

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...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.