Calculating dates

Greg Wills gwills at ozemail.com.au
Tue Apr 29 04:35:01 EDT 2003


Thanks Yves for this script. I did ask for a simple solution, wow this 
is quite something! I have had a look at it and an error or two popped 
up, so I will have a look at it more closely so that I can understand 
fully what you have written. I appreciate you putting me onto the right 
track. If I get stuck I may have to get back to you in a week or so. 
Thanks.

regards

Greg



> Message: 8
> Date: Sun, 27 Apr 2003 09:04:05 +0200
> To: use-revolution at lists.runrev.com
> From: yves COPPE <yvescoppe at skynet.be>
> Subject: Re: Calculating dates
> Reply-To: use-revolution at lists.runrev.com
>
>> Hi everyone
>>
>> I have been playing with this but can't get it to work. I want to
>> calculate ages of students from dates of birth and current date. If
>> I convert these dates to seconds, subtract the birth date from the
>> date entered - is there a simple way to then convert this number
>> into years, months and days?
>>
>> cheers
>>
>> Greg
>>
>
>
> Here is a script :
>
> answer whichage(<yourbirthday>,<today>)
>
> answer whichage(<"22/12/1967","27/03/2003")
>
> function whichage fromwhich,towhich
>    set the centuryCutoff to 01
>    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
>
>
> Hope this help.
> -- 
> Greetings.
>
> Yves COPPE
>
> Email : yvescoppe at skynet.be
>
  



More information about the use-livecode mailing list