SELECT * FROM hr.Employees;
SELECT firstname,
lastname,
(CASE WHEN (month(getdate()) > month(birthdate))
THEN datediff(yy,birthdate,getdate())
ELSE datediff(yy,birthdate,getdate()) -1
END) AS _years, --years
(CASE WHEN (month(getdate()) > month(birthdate))
THEN month(getdate()) - month(birthdate)
ELSE month(getdate()) - month(birthdate) +12
END) AS _months, --months
(CASE WHEN (day(getdate()) > (day(birthdate)))
THEN day(getdate()) - day(birthdate)
ELSE month(getdate()) - month(birthdate) +11 & day(getdate()) + (day(EOMonth(birthdate)) - day(birthdate))
END) AS _days --days
FROM hr.Employees
Here is the code for finding age in yy,mm,dd. The problem I am having is in the days section.
I want to do is (if current day < birthdate day )
then (currentMonth-birthmonht)+11 and day(getdate()) + (day(EOMonth(birthdate)) - day(birthdate))
.