Computing the age of a person?

Sarah Reichelt sarah.reichelt at gmail.com
Thu May 14 16:44:10 EDT 2009


> Now we'll wait for Sarah R. to come on board and show us how it's really
> done!


I think you've already got it, but I couldn't resist this challenge.... :-)

>From my DateTime library
<http://www.troz.net/Rev/libraries/DateTime.rev.gz> I took the
following function:

-- daysBetween(date1, [date2])
--
-- Returns the number of days between 2 dates.
-- If only one date is specified, it will use the current date for the second.
-- The dates must be in English format.
-- It doesn't matter whether the most recent date is first or last.
-- 
function daysBetween pDate1, pDate2
    if pDate2 is empty then put the short english date into pDate2
    if pDate1 is not a date or pDate2 is not a date then return empty

    convert pDate1 from short english date to dateItems
    convert pDate2 from short english date to dateItems
    repeat with i = 4 to 7
        put 0 into item i of pDate1
        put 0 into item i of pDate2
    end repeat
    convert pDate1 from dateItems to seconds
    convert pDate2 from dateItems to seconds

    put abs(pDate1 - pDate2) into tDiff
    return tDiff / (60 * 60 * 24)
end daysBetween

This gives you the number of days between a pair of dates, so you can
then divide by 365 to get the approximate number of years. I guess
there would be extra credit for working out how many leap years were
in that period and dividing by 365.xx instead for a more accurate
result.

BUT, I understand that there are problems with the convert command on
Windows systems if the year is < 1970, so this may not work properly
in those cases.

Cheers,
Sarah



More information about the use-livecode mailing list