Results 1 to 11 of 11

Thread: Age Calculator

  1. #1
    Join Date
    Dec 2005
    Posts
    1

    Unanswered: Age Calculator

    Can someone please help me find the Objectpal code (Paradox) for automatically calculating a person's age in years when the year of birth (mm/dd/yyyy) and the date of death (mm/dd/yyyy) are entered.

    Thanks in advance

  2. #2
    Join Date
    Aug 2003
    Location
    Bologna - Italy
    Posts
    209
    Simply subtract the birth year from the death year, then create a date with the day and month of death and the year of birth: if this date is > that the birth date, add 1 to age.

    End of algorithm!
    The only failure is not trying to do it.

  3. #3
    Join Date
    Sep 2003
    Location
    Dallas
    Posts
    182

    Alternatively

    You can take the subtract birthdate from date of death divide by 365.25 and take the integer value of that number and you will achieve a quick result. Of course this will not account for the millenium correction.

    Lonnie.

  4. #4
    Join Date
    Oct 2006
    Posts
    2

    Code for age calculation

    Hello,

    I've problems with the age calculating too.

    #Field1 has value 18-11-1977
    #Field2 has value 31-10-2006

    Can someone please give an example of the needed code to calculate the age?

    Thank you in advance.

    Regards, Ramon.

  5. #5
    Join Date
    Nov 2006
    Location
    Brighton, UK
    Posts
    11
    Mate, this is always easy.
    calculate the days from Day Zero. At least roughly.
    you'll need a variable capable of storing quite a huge number.
    How many days have passed from Day Zero to the date in Field #1?
    roughly: 1977*365 (days in a year) + 11*30(days in a month) + 18;
    there is your number1
    calculate the other number as well.
    subtract (any one of these from the other one) and use ABS function to get rid of the minus sign. There is the number of DAYS between those two dates.
    Practically, all you need to find out the age is DIVIDE the number of days by 365 and you'll get the age and some decimals that you won't need. This will work quite well; hey- and if there really is some need for even more precission, use decimals in your calculations. (like a year has actually 365.25 days, as there are 365 days and 6 hours in a year, not every month has 30 days... and so on... but practically this should work just fine for the purpose)

    [even though there ARE easier ways of obtaining the number of days between the two dates...]
    Oh, OK, I'll give full details, as I have really nothing to do...

    The TDateTime type consists of two parts: Date (stored as the integer part of a real value) [decimal point] Time (stored in the decimals) You can get at the DATE part of it by simply rounding the real value DOWN. Use FLOOR function (if available) to get just the integer value of your DateTime-type variable. Don't worry too much what exctly this number stands for, as there is no need to know (it's actually number of days passed since 1.1.1850 I think...) Rounding down both of your variables with the DateTime-s stored in them, you will get what you need to ABS(D1-D2) and then calculate the number of years from the Day delta you get.
    code would look like this:

    moment1,moment2:TDateTime;
    d1,d2,DeltaD, AGE: integer;

    d1 := floor(moment1);
    d2 := floor(moment2);
    DeltaD := ABS (d1-d2);
    AGE := floor(deltaD / 365.25); // very precise calculation - note the floor function as we don't want to add any unwanted years of age to a person

  6. #6
    Join Date
    Oct 2006
    Posts
    2
    Peter,

    Thank you for your clear and extensive information!

    Regards, Ramon.

  7. #7
    Join Date
    Aug 2003
    Location
    Bologna - Italy
    Posts
    209
    What an awful complicated mess!
    Why resorting to complicated day numbers calculations when it's very simple:

    (YearOfDeath-YearOfBirth)=Age
    if (deathmonth<birthmonth) or (deathmonth=birthmonth and deathday<birthday)
    Age=max(0,Age-1)
    endif

    That means: Age is the difference between birth year and death year, that should be reduced by one if the last birthday hasn't been passed.

    It's so simple an algorithm that you can even express it in simple SQL / QBE...
    The only failure is not trying to do it.

  8. #8
    Join Date
    Sep 2003
    Location
    Dallas
    Posts
    182

    Easiet

    Int((ddate-bdate)/365.25) = Age Years

  9. #9
    Join Date
    Nov 2005
    Posts
    2
    Or you could use the following expression in a calculated field. This works on one of my forms.
    int(longint(today()-[DoB])/365.25)

    Lewy

  10. #10
    Join Date
    Dec 2007
    Posts
    369
    not trying to get "the last word" on a topic.. but I'm always amazed that some people don't look at message dates when posting on a forum like this.. the original messages here were from 2005.. then a handful of people picked it up again, about a year later.. then this guy adds an idea a year after that..

    the best part, however, is most likely the fact that the OP never bothered to come back after asking the original question.. (g)
    --
    Steven Green - Myrtle Beach, South Carolina USA

    http://www.OasisTradingPost.com

    Oasis Trading Post
    - Collectibles and Memorabilia
    - Vintage Lego Sets and Supplies
    - and Paradox Support, too

  11. #11
    Join Date
    Aug 2003
    Location
    Bologna - Italy
    Posts
    209
    But if someone will search the forum for an age calculator, he'll find this post and all the useful answers, even if he's not the original poster...
    The only failure is not trying to do it.

Posting Permissions

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