Click here to Skip to main content
15,887,214 members
Articles / Database Development / SQL Server / SQL Server 2014
Alternative
Tip/Trick

Get accurate age by date

Rate me:
Please Sign up or sign in to vote.
4.80/5 (3 votes)
20 Feb 2010CPOL 4.5K  
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)



Comments and Discussions

 
-- There are no messages in this forum --