Search code examples
sql-serverdatediffdateadd

Calculating age based on a column that has only years in it in SQL Server


I have a column in my table Employee called BirthYear which stores only the year of birth and not the entire birthdate. I need to calculate the age of every employee using only the BirthYear data in SQL Server. How do I do it?


Solution

  • Here's your query to compute age

    select DATEPART(year, getdate()) - BirthYear from Employee