• martinez.math (11/16/2012)


    Simple way to compute your age accurately.

    A lot of query not exactly compute the age? yes! because sometime they only compute the datediff between DOB and datenow and divide it to 365.25 days and as a result they get a number with decimal something like 25 is the age with .06 decimal (age=25.06).

    In this query you exactly get the age as is it.

    Example 1

    DOB = 11/15/1987 and

    datenow =11/15/2012 the result would be

    AGE=25

    Example 2

    DOB = 11/14/1987 and

    datenow =11/15/2012 the result would be

    AGE=24

    SO HERE ARE THE QUERY

    DECLARE @DOB SMALLDATETIME

    SELECT @DOB = '11/15/1987'

    SELECT

    CASE

    WHEN MONTH(@DOB) >= MONTH(GETDATE()) AND DAY(@DOB) >=DAY(GETDATE()) THEN DATEDIFF(YY,@DOB,GETDATE())

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

    END AS AGE

    HOPE I CAN HELP! 🙂

    You just responded to a three-year-old post!

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.