If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Corel Paradox > Age Calculator

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-07-05, 11:47
Jose Rivera Jose Rivera is offline
Registered User
 
Join Date: Dec 2005
Posts: 1
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
Reply With Quote
  #2 (permalink)  
Old 12-08-05, 08:31
Shores Shores is offline
Registered User
 
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.
Reply With Quote
  #3 (permalink)  
Old 12-12-05, 15:31
Maroonotmoron Maroonotmoron is offline
Registered User
 
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.
Reply With Quote
  #4 (permalink)  
Old 10-31-06, 15:38
pinokkio pinokkio is offline
Registered User
 
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.
Reply With Quote
  #5 (permalink)  
Old 11-04-06, 22:15
MasterPeter MasterPeter is offline
Registered User
 
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
Reply With Quote
  #6 (permalink)  
Old 11-05-06, 08:50
pinokkio pinokkio is offline
Registered User
 
Join Date: Oct 2006
Posts: 2
Peter,

Thank you for your clear and extensive information!

Regards, Ramon.
Reply With Quote
  #7 (permalink)  
Old 01-28-07, 09:37
Shores Shores is offline
Registered User
 
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.
Reply With Quote
  #8 (permalink)  
Old 02-21-07, 17:40
Maroonotmoron Maroonotmoron is offline
Registered User
 
Join Date: Sep 2003
Location: Dallas
Posts: 182
Easiet

Int((ddate-bdate)/365.25) = Age Years
Reply With Quote
  #9 (permalink)  
Old 01-16-08, 11:09
Lewy18 Lewy18 is offline
Registered User
 
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
Reply With Quote
  #10 (permalink)  
Old 01-16-08, 13:15
Steve Green Steve Green is offline
Registered User
 
Join Date: Dec 2007
Posts: 282
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
Reply With Quote
  #11 (permalink)  
Old 02-08-08, 08:12
Shores Shores is offline
Registered User
 
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On