StumbleUpon
Share on Facebook

Monday, April 16, 2007

GetAge - Get Age Using SQL Query

How to calculate Age using SQL Query

DateDiff function can be used to get the Age from the birth date

Select BirthDate, DateDiff(year, BirthDate, getdate()) as Age from HumanResources.Employee

4 comments:

Unknown said...

That only works for users that have had their birthday already this year. If the users birthday is after the current date, the age is off by 1 year.

Anonymous said...

Datediff function worked perfectly for me.

Anonymous said...

Does not work.......

Sai Kumar Shailu said...


it will work...it will show in negative valueas a age in months...

Select BirthDate, DateDiff(month, BirthDate, getdate()) as Ageinmonths from HumanResources.Employee

http://www.w3schools.com/sql/func_datediff.asp

Related Posts Plugin for WordPress, Blogger...