ADMIN_GetAgeInYears

Deprecated. Don't use for new development and try to migrate existing uses.

Type: Scalar function

This function returns the number of completed years that separates two given dates, i.e. if the true difference is one and a half year, then this function returns a value of one year etc.

This is the type of calculation usually performed when reporting the age of a person.

Note:
A common misconception is that the function datediff(year, @Date1, @Date2) can be used to achieve the same result as described above.

This is false as what it really returns is the difference between the year values of the two dates, i.e. something functionally identical with year(@Date2) - year(@Date1).

Return value: int

The difference in completed years.

Parameters

@CreationDate mandatory datetime
The first date in the comparison.
@CompareDate mandatory datetime
The second date in the comparison. If set to DEFAULT then getdate() is used.