Best Way to Calculate Age

  • Since all provided answers were actually wrong (even though #2 seemed to provide a more accurate answer than #1 or #3), noone should lose any points for attempting to answer the question, so we should get our points back.

    😎

  • Lynn Pettis (3/7/2008)


    Since all provided answers were actually wrong (even though #2 seemed to provide a more accurate answer than #1 or #3), noone should lose any points for attempting to answer the question, so we should get our points back.

    😎

    Oops.

    I'm sorry if my previous reply offended you. It was not to be taken too seriously. I just keep making the mistake of underestimating how serious some people take their QotD score.


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

  • No offense taken, just restating why everyone who did answer should not be penalized for answering the QotD. I will admit I answered #2, and it returned the correct answer for my birthdate.

    😎

  • 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 Kornelis (3/7/2008)


    I just keep making the mistake of underestimating how serious some people take their QotD score.

    ...this coming from someone who has 100% QotD score....:D

    If it was easy, everybody would be doing it!;)

  • I'm not sure which part of my brain is missing, but I didn't SEE any third answer (which supposedly the correct on). I'm glad it's the 100% correct answer, but could you put it on the forum please?

    Thanks,

    j macdonald

  • 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 Kornelis (3/7/2008)


    I just keep making the mistake of underestimating how serious some people take their QotD score.

    ...this coming from someone who has 100% QotD score....:D

    100% attempted. Or, in other words, I picked an answer on each QotD from the very first that was available on the site when I first got here, on to the last. Except this one that is.

    I do get questions wrong (19%, according to the scoreboard). And I have gotten questions wrong because of errors in the question or in the answers and never (as far as I recall) asked for points back. When I ask for correction of a QotD, it is because I hate to see incorrect information on a site with as much impact on the community as SQL Server Central.


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

  • My birthday is today, both 2nd and 3rd answers produced incorrect result while 1st one gave a correct one

  • But you have to test birthdates that are today, tomorrow, yesterday, January 1, April 21, February 29, November 3, etc...

    ...because your code has to work 100% of the time!

    If it was easy, everybody would be doing it!;)

  • Hugo Kornelis (3/7/2008)


    Lynn Pettis (3/7/2008)


    So, based on all the comments so far, does everyone agree we all should get our 2 points?

    Perhaps a poll should be setup.

    😎

    I'd rather say that noone who answered the question should get any points. After all, whatever you answered, you got it wrong 😛

    Only those who were able to see that all queries are wrong and hence didn't answer the QotD at all should get any points.

    Then again, maybe I'm biased... :Whistling:

    (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)

    The function I posted earlier should return the correct info:

    http://www.wisesoft.co.uk/Articles/SQL%20Server/fAgeCalc.aspx

    Leap years should not be a problem.

    DBA Dash - Free, open source monitoring for SQL Server

  • Lynn Pettis (3/7/2008)


    No offense taken, just restating why everyone who did answer should not be penalized for answering the QotD.

    😎

    Steve Jones has said that nobody loses points for choosing a wrong answer on QoD. You just don't gain any points.

    Greg

  • But it is counted as points attempted, and therefore affects your % correct. If all the answers are wrong, we shouldn't get penalized for selecting a wrong answer.

    😎

  • Third solution is incorrect, I like my solution the best

    declare @DateOfBirth as datetime

    set @DateOfBirth = '2/13/1979'

    --Incorrect

    select DATEDIFF(yy, @DateOfBirth, GETDATE()) - CASE WHEN DATEPART(m, @DateOfBirth) >= DATEPART(m, GETDATE()) AND DATEPART(d, @DateOfBirth) >= DATEPART(d, GETDATE()) THEN 0 ELSE 1 END

    -- Best way to do it

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

  • Hugo Kornelis (3/7/2008)


    I picked an answer on each QotD from the very first that was available on the site when I first got here, on to the last. Except this one that is.

    Very cool! 😎

    I do get questions wrong (19%, according to the scoreboard).

    ...oh good, so you are human like the rest of us (at least most of us)! :hehe:

    If it was easy, everybody would be doing it!;)

  • After the discussion that this has escalated in to, most of you guys have had more than 2 points added to your site scores anyway after all your posts.....

    I thought I'd add this one and then I've got my two points even it does trash my QotD %age. 😀



    Ade

    A Freudian Slip is when you say one thing and mean your mother.
    For detail-enriched answers, ask detail-enriched questions...[/url]

  • 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 old on March 4 2004.

    See another post of mine a few screens back for the only three correct methods I've seen so far in this thread.


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

Viewing 15 posts - 91 through 105 (of 189 total)

You must be logged in to reply to this topic. Login to reply