Computing the age of a person?

J. Landman Gay jacque at hyperactivesw.com
Thu May 14 11:17:58 EDT 2009


klaus at major.on-rev.com wrote:
> Hi all,
> 
> I could need a hint on how to compute the age of a person when I have 
> the birthday.
> The "convert to seconds" and "subtract"ion part is easy, but how to 
> proceed? :-)

My variation, if all you need is the year:

function getAge pDate
    put the date into tNow
    convert pDate to dateitems
    convert tNow to dateitems
    repeat with x = 1 to 3
       put item x of tNow - item x of pDate & comma after tAge
    end repeat
    if item 2 of tAge < 0 or item 3 of tAge < 0
    then subtract 1 from item 1 of tAge
    return item 1 of tAge
end getAge

Items 2 and 3 can return negative numbers. If you need to know the 
months and days too, then you'd need to loop backward through the 3 
items, subtracting from the preceding item if the number if negative.

-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com



More information about the use-livecode mailing list