Results 1 to 12 of 12

Thread: [RESOLVED] Age Calculation

  1. #1

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Resolved [RESOLVED] Age Calculation

    Lets say you are born on 1/1/2000 @ 12:00:01 AM. You are one day old correct?

    On 1/2/2000 you are 2 days old.

    On 1/8/2000 you are 1 week old.

    On 1/15/2000 you are 2 weeks old.

    On 12/31/2000 you are 366 days old. (leap year)

    Therefore, on 1/1/2001 aren't you 1 year and 1 day old?

    I ask because I have an issue with an age calculator that I wrote.
    Last edited by dbasnett; Feb 15th, 2009 at 10:06 AM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  2. #2
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Boston, MA
    Posts
    391

    Re: Age Calculation

    Hi DBasnett,

    I think you meant 1/1/2001 on the last line of your post. I think you're right. At least as far as we casually consider our ages. I suppose you could calculate the number of days that have elapsed from birth to current and then divide by 365.24 (and how many other decimal places that I don't know) to figure out a more precise age. I guess it depends on how you want to look at what a year is.

  3. #3

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Age Calculation

    thanks for the catch, i fixed it in the original. i am still working on it, trying to have it both ways without creating a huge kludge. it works great, including leap years, for everything but the anniversary date (birth date).
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  4. #4
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Boston, MA
    Posts
    391

    Re: Age Calculation

    what's the problem with the anniversary date?

  5. #5

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Age Calculation

    anniversary is a date in the past, like birthday. here are my results:

    birthday = 1/1/2000 - 2000 is leap year

    On 1/1/2000 - 0 days old
    On 1/2/2000 - 2 days old
    On 1/8/2000 - 8 days old
    On 12/31/2000 - 366 days old
    On 1/1/2001 - 1 year 0 days old
    On 1/2/2001 - 1 year 2 days old
    On 12/31/2001 - 1 year 365 days old
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  6. #6
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Boston, MA
    Posts
    391

    Re: Age Calculation

    hmm... I just thought of something. I think it would make sense to define a year with a fractional number of days (365.24...) and just divide the number of days by that number to get their age.

    The reason I think you should go that way is, what happens if say someone is born March 1 in a leap year. After how many days would they be considered 1 year old according to the calculator?


    Edit: Shouldn't a year be the same number of days even if it is a leap year? a leap year just adds an extra day before we can change the calendar year, it doesn't add another day to an actual year.
    Last edited by wy125; Feb 15th, 2009 at 10:49 AM.

  7. #7
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Age Calculation

    Quote Originally Posted by dbasnett
    Lets say you are born on 1/1/2000 @ 12:00:01 AM. You are one day old correct?
    I kind of take issue with this statement.

    Are you saying that at one second into your life you are one day old?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  8. #8

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Age Calculation

    format of output

    birthday asOfDate age

    method1
    1/1/2000 1/1/2000 yrs = 0 days = 1
    1/1/2000 1/2/2000 yrs = 0 days = 2
    1/1/2000 12/31/2000 yrs = 0 days = 366
    1/1/2000 1/1/2001 yrs = 1 days = 1
    1/1/2000 1/2/2001 yrs = 1 days = 2
    1/1/2000 12/31/2001 yrs = 1 days = 365
    1/1/2000 1/1/2002 yrs = 2 days = 1
    1/1/2000 12/31/2004 yrs = 4 days = 366
    2/29/2000 3/1/2001 yrs = 1 days = 1
    2/29/2000 2/28/2003 yrs = 2 days = 365
    2/29/2000 3/1/2003 yrs = 3 days = 1
    2/29/2000 3/1/2004 yrs = 4 days = 2


    method 2
    1/1/2000 1/1/2000 yrs = 0 days = 0
    1/1/2000 1/2/2000 yrs = 0 days = 2
    1/1/2000 12/31/2000 yrs = 0 days = 366
    1/1/2000 1/1/2001 yrs = 1 days = 0
    1/1/2000 1/2/2001 yrs = 1 days = 2
    1/1/2000 12/31/2001 yrs = 1 days = 365
    1/1/2000 1/1/2002 yrs = 2 days = 0
    1/1/2000 12/31/2004 yrs = 4 days = 366
    2/29/2000 3/1/2001 yrs = 1 days = 0
    2/29/2000 2/28/2003 yrs = 2 days = 365
    2/29/2000 3/1/2003 yrs = 3 days = 0
    2/29/2000 3/1/2004 yrs = 4 days = 2
    Last edited by dbasnett; Feb 15th, 2009 at 11:05 AM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  9. #9

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Age Calculation

    i think this is the correct answer

    2000 and 2004 are leap years
    1/1/2000 1/1/2000 yrs = 0 days = 0
    1/1/2000 1/2/2000 yrs = 0 days = 1
    1/1/2000 12/31/2000 yrs = 0 days = 365
    1/1/2000 1/1/2001 yrs = 1 days = 0
    1/1/2000 1/2/2001 yrs = 1 days = 1
    1/1/2000 12/31/2001 yrs = 1 days = 364
    1/1/2000 1/1/2002 yrs = 2 days = 0
    1/1/2000 12/31/2004 yrs = 4 days = 365
    2/29/2000 3/1/2001 yrs = 1 days = 0
    2/29/2000 2/28/2003 yrs = 2 days = 364
    2/29/2000 3/1/2003 yrs = 3 days = 0
    2/29/2000 2/29/2004 yrs = 4 days = 0
    2/29/2000 3/1/2004 yrs = 4 days = 1
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  10. #10

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Age Calculation

    final test
    Code:
    2/29/1008   3/1/2009   yrs = 1001     days = 0
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  11. #11

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Age Calculation

    thanks for helping everyone. i had been thinking about this since early yesterday afternoon. it is funny how something so simple can get hard if you think about it too much.

    Code:
    2/29/1008    2/28/2009    yrs = 1000    days = 365
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  12. #12
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [RESOLVED] Age Calculation

    You are one day old on the second day, because the first day has completed. It's similar to you being one year old after the completion of a year.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width