-1

I want to find age from mysql database field name birthday. Ex. if anyone's data of birth is 25-07-1991 then i want to query his present age from mysql database. please someone help me.

  • Possible duplicate of http://stackoverflow.com/questions/5773405/calculate-age-in-mysql-innodb – Peter Featherstone Feb 10 '16 at 10:53
  • This should help: [Calculate age](http://stackoverflow.com/questions/5773405/calculate-age-in-mysql-innodb) in combination with a simple WHERE birthday = date – JazzCat Feb 10 '16 at 10:54

2 Answers2

1

I don't know if I've correctly understanded the question. The query could be something like:

SELECT * FROM table WHERE birthday = '1991-07-25'

If you want to get the age instead, I will try making a query like this:

SELECT (CURDATE()-birthday) FROM table WHERE ?

or I will make it via code, doing first a query to get the date of birth like:

SELECT birthday FROM table WHERE ?

and than doing a subtraction

0

If birthday is the name of the field containing the date of birth, you could do something like this:

SELECT YEAR(NOW()) - YEAR(birthday) FROM table WHERE ?;
stravanato
  • 146
  • 6