ColdCoffee (5/26/2010)
You can use DATEDIFF function:LIke:
SET DATEFORMAT DMY
SELECT DATEDIFF(yy,'21-03-1985',GETDATE()) AGE
Since DateDiff returns the number of boundaries crossed in comparing these two dates, it will report the wrong age if today's date is not >= your DOB. So, use this instead:
SELECT CASE WHEN datepart(dayofyear, GetDate() ) >= datepart(dayofyear, @DOB)
THEN DATEDIFF(yy,@DOB,GETDATE())
ELSE DATEDIFF(yy,@DOB,GETDATE()) -1
END AGE
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes