Getting the exact Birth Date

vishalneeraj-24503
Posted by vishalneeraj-24503 under Sql Server category on | Points: 40 | Views : 352
We will use Floor and DateDiff in-built Sql Server function as follows:-
SELECT (FLOOR(DATEDIFF(DAY,'2000-07-14', GETDATE()) / 365.25)) 'Current Age'

OutPut
14

Explaination:- In above query,we have passed DOB as 2000-07-14 means 14 July 2000,and also notice that July has been passed now and august has come,that is the reason we are getting 14 Years.
SELECT (FLOOR(DATEDIFF(DAY,'2000-12-14', GETDATE()) / 365.25)) 'Current Age' 

OutPut
13

Explaination:- In above query,we have passed DOB as 2000-12-14 means 14 December 2000,and also notice that December has Not come Yet,that is the reason we are getting 13 Years.

Comments or Responses

Login to post response