Sunday, April 25, 2010

Accurate Age Calculation

I was just doing an SQL statement which need to calculate the age of an employee accurately, accurately means the rate is applied to get a benefit is based on the age, so a day is matter too,

So the easiest way to calculate that is Calculate the days between the DOB and the current date and divide by 365.25 ( 0.25 - beacuse leap year)

So the function came out as follows


FLOOR(DATEDIFF(day, DOB, TodayDate) / 365.25)

No comments:

Post a Comment