Getting Age from given Date.

vishalneeraj-24503
Posted by vishalneeraj-24503 under Sql Server category on | Points: 40 | Views : 364
Write below Query:-
DECLARE @DATE_OF_BIRTH_1 AS DATETIME = '2000-07-14';
DECLARE @DATE_OF_BIRTH_2 AS DATETIME = '2000-12-14';

SELECT (FLOOR(DATEDIFF(DAY,@DATE_OF_BIRTH_1,GETDATE()) / 365.25)) Age1
SELECT (FLOOR(DATEDIFF(DAY,@DATE_OF_BIRTH_2,GETDATE()) / 365.25)) Age2
SELECT (FLOOR(DATEDIFF(DAY,@DATE_OF_BIRTH_3,GETDATE()) / 365.25)) Age3

Output:-
1) - 14
2) - 13
3) - 29

Comments or Responses

Login to post response