Thursday, May 23, 2013

Age Calculation: Oracle vs. SQL Server

Oracle months_between(sysdate, dob)/12
SQL server year(getdate()) - year(dob) + (month(getdate()) - month(dob))/12.0 + (day(getdate()) - day(dob))/365.0

If you are only interested in the integer part of the age, here is an alternative method  for SQL server:
(cast(convert(varchar(8), getdate(), 112) as int) - cast(convert(varchar(8), dob, 112) as int))/10000

No comments: