Calculate Year, Month and Day between Current and specified Date in SQL Server

Last Reply 7 months ago By dharmendr

Posted 7 months ago


i have datetime field in sql, i want to fetch age calculation in sql query like 

dob: 01/01/1983

sql query to return

Years- Months- Days  (36 Year, 2 Months, 5 days) 

please advice

Posted 7 months ago


select SName,
CAST(DATEDIFF(yy, DOB,getdate()) AS varchar(4)) +' Years, '+ 
CAST(DATEDIFF(mm, DATEADD(yy, DATEDIFF(yy, DOB, getdate()), DOB), getdate()) AS varchar(2)) +' Month,and '+ 
CAST(DATEDIFF(dd, DATEADD(mm, DATEDIFF(mm, DATEADD(yy, DATEDIFF(yy, DOB, getdate()), DOB), getdate()), DATEADD(yy, DATEDIFF(yy, DOB, getdate()), DOB)), getdate()) AS varchar(2)) +'Days' AS Ages 
FROM tblData


Posted 7 months ago

thank you but it looks very long query, is there any short version of it