Its all about structured query language (SQL) - SQL Query Snippets, LINQ Snippets, SQL Stored Procedures, SQL Server Articles, SQL Server Feeds, SQL Server Analytics, SQL Server Integration Services (SSIS), Microsoft SQL Server BIG DATA - HortonWorks, SQL Server CRM Integration
Pages
▼
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
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.
ReplyDeleteDatediff function worked perfectly for me.
ReplyDeleteDoes not work.......
ReplyDelete
ReplyDeleteit 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