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
https://forums.phpfreaks.com/topic/260033-date-and-age-problem/
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.

Archived

This topic is now archived and is closed to further replies.

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