• WayneS (5/26/2010)


    ColdCoffee (5/26/2010)


    You can use DATEDIFF function:

    LIke:

    SET DATEFORMAT DMY

    SELECT DATEDIFF(yy,'21-03-1985',GETDATE()) AGE

    Since DateDiff returns the number of boundaries crossed in comparing these two dates, it will report the wrong age if today's date is not >= your DOB. So, use this instead:

    SELECT CASE WHEN datepart(dayofyear, GetDate() ) >= datepart(dayofyear, @DOB)

    THEN DATEDIFF(yy,@DOB,GETDATE())

    ELSE DATEDIFF(yy,@DOB,GETDATE()) -1

    END AGE

    That perfectly makes sense!

    How sweet it is to start the day with learning a titbit.. wow

    Thanks Wayne Shef! 🙂