HyperCard: Calculating Age (7/92)

Here's a HyperCard handler that accurately calculates a person's age.

on calcAge

put the date into curDate
convert curDate to seconds
put curDate + 86400 into curDate
convert curDate to dateItems
put item 1 of curDate into curYear

put background field "BDay" into Birth
convert Birth to seconds
put Birth + 86400 into Birth
convert Birth to dateItems
put item 1 of Birth into BYear

put curYear - BYear into tempAge

Put 1900 into item 1 of curDate
convert curDate to seconds

put 1900 into item 1 of birth
convert birth to seconds

if curDate < birth then
put tempAge - 1 into tempAge
end if

put tempAge into background field "Age"

end calcAge

Where BDay is a background field containing a birthdate and Age is a
background field into which the calculated age will be placed.


This article is adapted from the Claris Tech Info database.
Published Date: Feb 19, 2012