I'm trying to practice the dates in livecode its kinda tricky. I was able to find a script that would get the age upon learning dates on livecode. here is the script below.
Questions
1. I want to put a button that will check the birth date on my datagrid and will automatic increment the age once it reached it's birth date and it will update into my database (sqlite) but I don't know where to start
2. Is there a shorter script code on how to get the age? aside from the script below.
Thanks
Code: Select all
on mouseUp --age
put fld "BirthDate" into tBirthdate
if tBirthdate = empty then answer "no entered birthdate"
if number(words in tBirthdate) = "1" and item 1 of tBirthdate is a number and item 1 of tBirthdate >= "1" and item 1 of tBirthdate <= "12" and \
item 2 of tBirthdate is a number and item 2 of tBirthdate >= "1" and item 2 of tBirthdate <= "31" and \
item 3 of tBirthdate is a number and length(item 3 of tBirthdate) = "4" then
set the itemDel to "," --default
end if
put age(tBirthdate) into fld "Age"
end mouseUp
function age Birthdate --age("mm/dd/yyyy") [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
end age