function stsDateMath pDate1,pOperation,pNumberOrDate2,pReturnVal
set the useSystemDate to true
convert pDate1 to seconds
if the result is "invalid date" then return "STSError: Invalid Date"
if isNumber(pNumberOrDate2) then
-- adding/subtracting date chunks
switch pReturnVal
case "hour"
case "hours"
case "hr"
case "hrs"
put (pNumberOrDate2 * 60 * 60) into tVal
break
case "min"
case "mins"
case "minute"
case "minutes"
put (pNumberOrDate2 * 60) into tVal
break
case "days"
case "day"
put (pNumberOrDate2*86400) into tVal
break
case "week"
case "weeks"
put (pNumberOrDate2*86400*7) into tVal
break
end switch
do "put (" & pDate1 && pOperation && tVal & ") into tRetVal"
convert tRetVal to short date and short time
else
convert pNumberOrDate2 to seconds
if the result is "invalid date" then return "STSError: Invalid Date"
do "put (" & pDate1 && pOperation && pNumberOrDate2 & ") into tRetVal"
if pOperation = "-" then
switch pReturnVal
case "min"
case "mins"
case "minute"
case "minutes"
return (tRetVal/60)
break
case "days"
case "day"
return (tRetVal/86400)
break
case "week"
case "weeks"
return ((tRetVal/86400)/7)
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
end if
return tRetVal
end stsDateMath