Find out age using SQL

database
mysql

#1

Hi I'm using sql to find out how old someone is. Im doing this using columns Name, Date of birth and todays date.

I used this query below and it works.

SELECT DOB, CURDATE() AS TODAY ,TIMESTAMPDIFF(YEAR,DOB,CURDATE()) AS AGE FROM data

I was just wondering if this is the best way to find a person's age or is there a better way of writing this or more effiecient way.

Any help would be much appreciated


#2

you're good

(i wasn't sure so i tested it, and i could detect no rounding issues with dates such as birthday being tomorrow)


closed #3

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.