• David. (8/27/2009)


    This demonstrates that the datediff solution does not change the age at the time of the birthdate. All the age results are the same:

    declare @BirthDate DATETIME

    set @BirthDate = '08/27/1980'

    print @BirthDate

    print getdate()

    SELECT 'DATEDIFF AGE = ', DATEDIFF(YEAR, @birthdate , GETDATE())

    print 'TODAY IS THE TWENTY-SIXTH'

    set @BirthDate = '08/26/1980'

    print @BirthDate

    print getdate()

    SELECT 'DATEDIFF AGE = ', DATEDIFF(YEAR, @birthdate , GETDATE())

    set @BirthDate = '08/25/1980'

    print @BirthDate

    print getdate()

    SELECT 'DATEDIFF AGE = ', DATEDIFF(YEAR, @birthdate , GETDATE())

    set @BirthDate = '08/24/1980'

    print @BirthDate

    print getdate()

    SELECT 'DATEDIFF AGE = ', DATEDIFF(YEAR, @birthdate , GETDATE())

    Your right, DATEDIFF(yy, @birthdate, getdate()) will return the same value regardless if the @birthdate is before on or after GETDATE(). That is the nature of the DATEDIFF function. TO actually calculate age requires additional calculations to make the final determination.

    Consider this, DATEDIFF(yy,'2008-12-31','2009-01-01') returns 1 as there is a difference in year periods is 1 even though there is actually only a difference of 1 day.