SUB_DAYS
Use the SUB_DAYS script function to subtract a number of days from a date. You can optionally restrict the calculation to days defined in a Calendar Event.
Syntax
SUB_DAYS ([Date Format:]Date, Days[, Calendar, Calendar Event])
Parameters
| Parameter | Description | Format |
|---|---|---|
| Date | Date in YYMMDD or YYYYMMDD format. The date format applies to both the input date and the returned date. To use a different format, enter the desired format followed by a separator (: or ;) before the date. | script literal or script variable |
| Days | Number of days to subtract from the date. Tip: Specify 0 days to validate a date against a Calendar object. If the date is valid, the function returns it unchanged. If not, it returns the previous valid date based on the calendar. |
script literal, number without quotation marks, or script variable |
| Calendar
(Optional) |
Name of a Calendar object. When specified, only days defined in Calendar Events are included in the calculation. | AE name, script literal or script variable |
| Calendar Event
(Optional) |
Name of a Calendar Event. Required when a Calendar object is specified. | AE name, script literal or script variable |
Return Codes
The SUB_DAYS function returns the calculated date, or one of the following error codes:
| Return Value | Condition |
|---|---|
| 0 | No days are assigned to the Calendar Event, or the calculated date lies outside the calendar range. |
| 20327 | Calendar object does not exist. |
| 20328 | Calendar Event does not exist in the Calendar object. |
Note: The calendar calculation automatically considers the range of the specified calendar.
Examples
The following example subtracts two days from the specified date in the default YYMMDD format and prints the result (000330) in the activation report.
: SET &DATE# = SUB_DAYS ("000401" , 2)
: PRINT &DATE#
The following example lets a user specify a retention period. The script assigns the current date to a variable, prompts the user for a number of days using :READ, and subtracts that number from the current date.
: SET &CURRENTDATE# = SYS_DATE ()
: READ &NUMBER#, "00", "Enter how many days you want to store", "08" ,N
: SET &RETDATE# = SUB_DAYS (&CURRENTDATE#, &NUMBER#)
The following example retrieves the current date in a custom format and subtracts two days. The custom date format is specified directly in the SUB_DAYS call.
: SET &CURDATE# = SYS_DATE ("DD.MM.YY" )
: SET &PWRKDAY# = SUB_DAYS ("DD.MM.YY:&CURDATE#" , 2)
See also: