Calculations Involving Dates
Ken Ray
kray at sonsothunder.com
Sat Nov 20 19:12:07 EST 2004
On 11/19/04 4:59 PM, "Gregory Lypny" <gregory.lypny at videotron.ca> wrote:
> Hello,
>
> The date format of my Mac is set to Day/Month/Year. Maybe I've been
> in front of the screen too long, but why does the following handler
> answer No? Does it mean that the only way to do date calculations is
> with date items?
Here's a handy date math function you can use if you like (comes out of my
STS Code Library in Scripter's Scrapbook):
function stsDateMath pDate1,pOperation,pDate2,pReturnVal
set the useSystemDate to true
convert pDate1 to seconds
if the result is "invalid date" then return "STSError: Invalid Date"
convert pDate2 to seconds
if the result is "invalid date" then return "STSError: Invalid Date"
do "put (" & pDate1 && pOperation && pDate2 & ") into tRetVal"
if pOperation = "-" then
switch pReturnVal
case "days"
put (tRetVal/86400) into tDays
return tDays
break
case "weeks"
put ((tRetVal/86400)/7) into tWeeks
return tWeeks
break
case "weeks,days"
put trunc((tRetVal/86400)/7) into tWeeks
put ((tRetVal-(tWeeks*7*86400))/86400) into tDays
return tWeeks,tDays
break
end switch
end if
return tRetVal
end stsDateMath
This way, you can do this:
put stsDateMath("9/6/1963", ">", "11/6/1963") --> "TRUE"
Hope this helps,
Ken Ray
Sons of Thunder Software
Web site: http://www.sonsothunder.com/
Email: kray at sonsothunder.com
More information about the use-livecode
mailing list