--this query finds the current ( as of the date the query is run) age of the person.
declare @dob datetime
set @dob = '07/12/1966'
select CASE
WHEN dateadd(year, datediff (year, @dob, GETDATE()),@dob) > GETDATE()
THEN datediff (year, @dob, GETDATE()) - 1
ELSE datediff (year, @dob, GETDATE())
END as Age
--select dateadd(year, datediff (year, @dob, GETDATE()),@dob)
--select datediff (year, @dob, GETDATE())
This blog is created to add all the information and experiences that I have learnt while working on MS sql server as a DBA. The blog is also updated frequently with the real world problem that I encounter hands on at work and the resolutions to resolve them. I hope this blog will be of some use to you and you will revisit. Thank you for stopping by and you are welcome to leave comments.
Showing posts with label age. Show all posts
Showing posts with label age. Show all posts
Monday, July 18, 2016
Subscribe to:
Posts (Atom)