Calculating dates
Greg Wills
gwills at ozemail.com.au
Fri May 2 22:07:01 EDT 2003
Hi all
I have had success with Yves script and some minor adjustments.
Is there a way to cover ages that cross over the "centuryCutoff"
setting? I found that the Mac still handles the script, but gives an
age - one hundred years out though. Windows just refuses to try to work
it out - "spits the dummy" at - put (item 1 of enddate - item 1 of
startdate) into diffan. (Even with the full year input.)
This script does what I had initially set out to do, however for use in
other situations, such as Genealogy, it is a bit limiting! Has anyone
played with this?
Yves, I was curious as to why you added this part of the script. When I
watch it in the Script Bug Mode, I don't see how it influences the
outcome - as it doesn't - but would be interested in your thinking and
intention as you put it in.
put startdate into temp
get last char of temp
repeat until it is not a integer
get last char of temp
delete last char of temp
end repeat
if it = "-" and it = "/" then exit to top
if param(2) = "" then
put mi_shortdate() into enddate
else put param(2) into enddate
put enddate into temp
get last char of temp
repeat until it is not a integer
get last char of temp
delete last char of temp
end repeat
Thanks again Yves and Sarah for your initial replies.
script so far - with the above section still included.
on mouseUp
ask "Date of Birth?"
put it into firstDate
ask "Date of Assessment?"
put it into secondDate
put whichage (firstDate, secondDate) into dateholder
put item 1 of dateholder into field "year"
put item 2 of dateholder into field "month"
put item 3 of dateholder into field "day"
end mouseUp
function whichage fromwhich,towhich
set the centuryCutoff to 35
set useSystemDate to true
if param(1) = "" then exit to top
put param(1) into startdate
put startdate into temp
get last char of temp
repeat until it is not a integer
get last char of temp
delete last char of temp
end repeat
if it = "-" and it = "/" then exit to top
if param(2) = "" then
put mi_shortdate() into enddate
else put param(2) into enddate
put enddate into temp
get last char of temp
repeat until it is not a integer
get last char of temp
delete last char of temp
end repeat
if it = "-" and it = "/" then exit to top
convert startdate to dateitems
convert enddate to dateitems
put (item 3 of enddate - item 3 of startdate) into diffjour
if diffjour < 0 then
add "1" to item 2 of startdate
get item 2 of enddate
if (it is in "1,3,5,7,8,10") or (it= "12") then put "31" into
correction
else if (it is in "4,6,9,11") then put "30" into correction
else if item 1 of enddate mod 4 = 0 then put "29" into correction
else put "28" into correction
add correction to item 3 of enddate
put (item 3 of enddate - item 3 of startdate) into diffjour
end if
put (item 2 of enddate - item 2 of startdate) into diffmois
if diffmois < 0 then
add "1" to item 1 of startdate
put (item 2 of enddate) + 12 into item 2 of enddate
put (item 2 of enddate - item 2 of startdate) into diffmois
end if
put (item 1 of enddate - item 1 of startdate) into diffan
return diffan&","&diffmois&","&diffjour
end whichage
More information about the use-livecode
mailing list