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
Subscribe to:
Post Comments (Atom)
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
4 comments:
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.
Datediff function worked perfectly for me.
Does not work.......
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
Post a Comment