Skip to main content
December 15, 2010
Answered

Translating date to age

  • December 15, 2010
  • 2 replies
  • 1054 views

Hello forum buddies.

I am trying to translate a date of birth in php. I collect a users date of birth and insert it into a php database as 30 character VARCHAR. I would like to query the date of birth and translate them into an age number how could I do this. The date of birth is collected using select menus like day month year and inserted as a varchar. How could I then translate that to a age number.

Thank you.

This topic has been closed for replies.
Correct answer David_Powers




Thanks again for the reply

Just for verification does the code below  then give a single  number age of the user i.e 25.

<?Php

/*The translation code then results*/

$userage=$row['age'];

echo $userage;

?>

Thanks again I will check out the cookbook when I can.


Tony404 wrote:

Just for verification does the code below  then give a single  number age of the user i.e 25.

Yes.

2 replies

Participating Frequently
December 15, 2010

>I collect a users date of birth and

>insert it into a php database as

>30 character VARCHAR.

It's generally a bad idea to store date data as anything other than date datatypes. The way the user interface works here is irrelevent. Take the user input, convert and store in the DBMS as a date.

December 16, 2010

Hi

I stored the date as a var because i was using 3 drop down menus day mon year and did not know how to pass the data through the date function

/* $date=date('','',''); */

So I just took the data from the drop down menus and inserted it into the varchar.

ultrasuite
Inspiring
December 16, 2010

I think the advice given above to use date datatype is sound.  You don't need to use varchar.  Use concatenation to convert the three values into date type format.

J.S.

http://www,ultrasuite.com/

December 15, 2010

What is the format of the birth date when it is sent to the database?

yyyy-mm-dd