Forum Replies Created

Viewing 15 posts - 3,211 through 3,225 (of 3,348 total)

  • RE: Best Way to Calculate Age

    Hi Scott & GSquared,

    My common sense was actually not about when a birthdate is (I have at times celebrated by birthday several days before or after the day I was...

  • RE: Best Way to Calculate Age

    GSquared (3/10/2008)


    Lynn and Hugo:

    I took Leap Years into account, and even (to be totally anal retentive about it), the hour, minute, second, and number of milliseconds, on each time.

    Maybe I'm...

  • RE: Best Way to Calculate Age

    GSquared (3/10/2008)


    Here's the function I recommend for this:

    select datediff(yy, @dateofbirth, getdate()) -

    case

    when dateadd(year,

    datediff(yy, @dateofbirth, getdate()),

    @dateofbirth) > getdate() then 1

    else 0

    end

    This takes the datediff, adds it back to the...

  • RE: Best Way to Calculate Age

    Lynn Pettis (3/10/2008)


    Here is a formula that appears to work okay in SQL Server:

    datediff(yy, @dob, @calcDate) - case when (datepart(dy, @calcDate) < datepart(dy, @dob)) then 1...

  • RE: Best Way to Calculate Age

    Jamie Longstreet (3/10/2008)


    I see Hugo's point. You cannot take into account leap years and other such anomalies when you are creating a calculation using months. Months are unreliable...

  • RE: Best Way to Calculate Age

    Rick Harker (3/10/2008)


    1) I see the same result. I used to go to school with a woman who claimed she was only 4 because of her leap year birthday. :)...

  • RE: Best Way to Calculate Age

    Jamie Longstreet (3/10/2008)


    Hugo,

    Not sure what you mean but I took the date you implied (37 years and 9 months ago) and ran the routine and came up with 37 and...

  • RE: Best Way to Calculate Age

    Rick Harker (3/10/2008)


    I would like to point out that my little proc has not been shown to be wrong... 🙂

    (I was hoping for some sort of feedback.)

    Sorry, Rick - I...

  • RE: Best Way to Calculate Age

    Jamie Longstreet (3/10/2008)


    Hugo,

    http://www.sizes.com/time/cal_gregorian.htm

    Try changing the Int to Round. Note that the calculation takes into account the factors you mentioned. I just put this one out there...

  • RE: Best Way to Calculate Age

    Hi Jamie,

    Interesting approach - but unfortunately, it shares the problem also exhibited by several other suggestions posted here, that it won't work correctly in non-leap years.

    For instance, the calculated difference...

  • RE: Best Way to Calculate Age

    Mohan Kumar (3/8/2008)


    Hence, none can provide correct answer all the time so most close answer is option 2.

    If you look back through the 12 pages of discussion, you'll see several...

  • RE: Best Way to Calculate Age

    Robert Price (3/8/2008)


    Reverse the values of 0 and 1 for the condition and else in the case statement and #3 is correct...

    I'm sure I wasn't the first to notice this...

  • RE: Best Way to Calculate Age

    louie.cowen (3/7/2008)


    Most people seem to be modifying the 3rd option to make it correct, but the best answer is what is the simplest, meets ALL the criteria (results in tinyint)...

  • RE: Best Way to Calculate Age

    mpeverill (3/7/2008)


    -- Best way to do it

    Select DATEPART( yyyy,Cast((Cast(GetDate() as decimal(9,2)) - Cast(@DateOfBirth as decimal(9,2))) as Datetime))-1900

    Nope. This formula says that someone born on March 5 2003 is 1 year...

  • RE: Best Way to Calculate Age

    Trader Sam (3/7/2008)


    Hugo Kornelis (3/7/2008)


    (still waiting for a correct answer to be added so that I can finally get back to my track record of 100% of all QotD's attempted)

    Hugo...

Viewing 15 posts - 3,211 through 3,225 (of 3,348 total)