Date Arithmetic |
Top Previous Next |
Various dates are saved in internal Robo-FTP script variables. For example, the current date is always saved in the %date variable.
Robo-FTP provides two script commands, DATEADD and DATESUB, that allow variables containing a date (i.e., any string in the format mm-dd-yy or mm/dd/yy) to be manipulated by adding or subtracting a specified number of days.
Robo-FTP also provides two script commands, DATETIMEADD and DATETIMESUB, that allow variables containing a date time (i.e., any string in the format Sat Feb 16 11.00.22 2013) to be manipulated by adding or subtracting a specified number of days, hours, minutes, or seconds depending on the option specified.
Sometimes you may need to construct date or time variables from external data. In that case you need to know that dates and times passed to Robo-FTP's date manipulation and date comparison functions are normalized. For example:
IFREGEX %date "([0-9]+)-([0-9]+)-([0-9]+)" SET month = %regex[1] SET day = %regex[2] SET year = %regex[3]
SETNUM yesterday = day - 1 ;; produces 0 on first day of month SET yesterdate = month + "-" + yesterday + "-" + year
GETNEXTFILE "*" IFERROR GOTO no_file_found ;;The following comparison works even on the first day of the month IFDATE< %nextfiledate yesterdate GOTO file_older_than_yesterday
In this case if the date were 01-01-16 then yesterdate would be 01-00-16 which would be normalized to 12-31-15 when IFDATE< performs the comparison with %nextfiledate.
See also: Using the %date, %datetime, and %time Variables
|