Link to home
Start Free TrialLog in
Avatar of Akhil Vinay Mandava
Akhil Vinay MandavaFlag for India

asked on

Automatically calculate the age after typing the birth date ?

can we automatically calculate the age after giving date of birth???
if yes please leave a code for me in comment.
ASKER CERTIFIED SOLUTION
Avatar of Dirk Strauss
Dirk Strauss
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Where do you want this calculation to occur? Commonly, the age is determined as needed since it changes.
Is this on the interface where you ask users for info, in this case you would/could client side scripting JavaScript onchange() of the year selection box.
I agree with arnold. The age is calculated from date of birth, so it is not only redundant info but info, that needs to be calculated from the date of birth, even if you only want the usual years age, which only changes once a year.

MySQL offers generated fields since version 5.7, but even having support for a calculated age column, it wouldn't help you for example to query all users having birthday within the next month or week, if the calculated age is bound to compute with current_timestamp or now().

I suggest you create a function computing an age based on dob and a second datetime, so you can compute age as of now or in a week or at the date of death or any other event of interest, then you can query that by agefunctionname(table.dobcolumn, now()) or similar calls within a query.

Bye, Olaf.