l i v e c o d e

stsDateMath
Mac OS 9 Mac OS X Windows Linux

Usage
stsDateMath(date1,mathOpereation,numberOrDate2,returnFormat)
put stsDateMath("9/26/03","+","4","days")
--> 09/30/03 2:00 AM
put stsGetFileListing("/Users/kenray/MyFolder",".jpg","true")
Description
Gets a list of full paths to files. You can format the result using stsFormatFileListing.
Code
Select the code below and copy it to the clipboard, or retrieve it from Scripter's Scrapbook Online.
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

 Print this code entry

News and Rumors Products Services Developer Resources Contact STS About STS