I have a kludgy past-date function. There must be a better elegant solution. Terry
Code: Select all
on mouseUp  --age
   set the itemDel to "/"
   repeat forever
      ask "If Elvis were alive, how old would he be? (mo/dy/year)" with "1/8/1935" titled "Age"
      if it = empty then exit to top
      if item 1 of it is a number and item 1 of it >= "1" and item 1 of it <= "12" and \
            item 2 of it is a number and item 2 of it >= "1" and item 2 of it <= "31" and \
            item 3 of it is a number and length(item 3 of it) = "4" then
         set the itemDel to ","  --default
         exit repeat
      end if
      beep
      answer "Please enter date as: MONTH 1-12 / DAY 1-31 / 4-digit YEAR" with "OK" titled "Age"
   end repeat
   answer "Birthdate:" && it &cr& "Age:" && age(it) & "." with "OK" titled "Age"
end mouseUp
function age Birthdate  --age("mo/dy/year")  [4-digit year] [handles windows dates < 1/1/1970]
   local NewerYear, NewerMonth, NewerDay, OlderYear, OlderMonth, OlderDay, AgeYear, AgeMonth, AgeDay
   convert date() to dateItems
   put item 1 of it into NewerYear
   put item 2 of it into NewerMonth
   put item 3 of it into NewerDay
   set the itemDel to "/"
   put item 1 of Birthdate into OlderMonth
   put item 2 of Birthdate into OlderDay
   put item 3 of Birthdate into OlderYear
   set the itemDel to ","  --default
   put NewerYear - OlderYear into AgeYear
   if NewerMonth < OlderMonth or NewerMonth = OlderMonth and NewerDay < OlderDay then subtract 1 from AgeYear
   put NewerMonth - OlderMonth into AgeMonth
   if AgeMonth < "0" or NewerDay < OlderDay then add 12 to AgeMonth
   put NewerDay - OlderDay into AgeDay
   if AgeDay < "0" then
      subtract 1 from AgeMonth
      add 30 to AgeDay  --approximate
   end if
   return AgeYear &&"years,"&& AgeMonth &&"months,"&& AgeDay &&"days"
end age
