Age calculation help - Forum

Forum Navigation
You need to log in to create posts and topics.

Age calculation help

Just lost a Veteran who was 104 years old (105 January 24, 2020) but the routine I developed gives the answer of 109.

Could someone tell me where it goes wrong? I seems to work with other birthdays.

". calculate age today
DateToNum "[AddrBook.Contacts.DOB]" "Default" "[NumResult]"
DateToNum "[DateShort]" "Default" "[Today]"
Math "[Today]-[NumResult]" "0" "[Result]"
Math "[Result]/365.25" "1" "[Result2]"
SearchStr "." "[Result2]" "[PosOfPeriod]" ""
StrDel "[Result2]" "3" "2" "[RemoveDec]"
AlertBox "Age Today" "Person is [RemoveDec] years old born [AddrBook.Contacts.DOB]"

@cssystems

Could someone tell me where it goes wrong? I seems to work with other birthdays.

A year is NOT exactly 365.25 days ... according to this web page ... https://en.wikipedia.org/wiki/Earth%27s_orbit ...

Earth orbits the Sun at an average distance of 149.60 million km (92.96 million mi),[1] and one complete orbit takes 365.256 days ... which is why EVERY fourth year is NOT a leap year (366 days)

... here is the set of rules that determine if a year is a Leap year (366 days) or not (365 days) ...

In the Gregorian calendar, three criteria must be taken into account to identify leap years:

The year can be evenly divided by 4;
If the year can be evenly divided by 100, it is NOT a leap year, unless;
The year is also evenly divisible by 400. Then it is a leap year.

So, 2000 was a leap year but 1700, 1800 and 1900 were NOT.

Try ...

Math "[Result]/365.256" "1" "[Result2]"

If this is still incorrect, display the value of [Result] ... and then use a spreadsheet (one row per year; then SUM the days for each year) to see where the discrepancy lies.

@CSSystems

Here is a Pub that I created to calculate the age of a concrete cylinder from it's creation (birth) to it's compressive strength test (death) in terms of days and hours. This does not calculate years because concrete cylinder life is not recorded in this way but this may help you calculate to the minute provided you can convert hours to days to years.

Uploaded files:
  • You need to login to have access to uploads.

Thanks for the input. However, I discover the flaw.

It had to do with my attempt to show only whole number.

SearchStr "." "[Result2]" "[PosOfPeriod]" ""
StrDel "[Result2]" "3" "2" "[RemoveDec]"
AlertBox "Age Today" "Person is [RemoveDec] years old born [AddrBook.Contacts.DOB]"

Example: Age calculated as 74.5 I would remove the 3rd character and 4th

i.e. start at 3rd (period) and remove 2 characters (period and 5).

Interesting enough when the age went over 100 I remove the 3rd  and forth characters

Example: Age 104.9 would result in removing 3 character (4) and the 4th (period) showing 109 as the age.

The New code is and leaving 1 decimal place. Seems to work proper now.

DateToNum "[AddrBook.Contacts.DOB]" "m/d/y" "[NumResult]"
DateToNum "[DateShort]" "Default" "[Today]"
Math "[Today]-[NumResult]" "0" "[Result]"
Math "[Result]/365.25" "1" "[Result2]"
AlertBox "Age Today" "Person is [Result2] years old born [AddrBook.Contacts.DOB]"

I could have used StrLen to remove period and decimal place by checking if StrLen=4 remove 3 and 4 character else If StrLen=5 remove 4th and 5th character. Decided to leave one decimal place so myself and other users how close the member is to next birthday.

Thanks for the help. It means a lot to have this forum to bounce ideas off of.

 

Well done CSSystems.