Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / database / SQL-Server / SQL-Server-2014

Get accurate age by date

4.80/5 (3 votes)
20 Feb 2010CPOL 4.6K  
Get accurate age by date using MS SQL Server
SQL
DECLARE @Age int
DECLARE @Date_of_birth datetime
DECLARE @Today varchar(11)
SELECT @Date_of_birth = '03/05/1979'
SELECT @Today = GETDATE()
SELECT @Age = FLOOR(DATEDIFF(day, @Date_of_birth, @Today) / 365.25)
PRINT 'Your age is: ' +  CONVERT(varchar, @Age)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)