SUB_DAYS
Use the SUB_DAYS script function to subtract a number of days from a given date. This function lets you optionally calculate the date depending on Calendar Events defined in a Calendar object.
Syntax
SUB_DAYS ([Date Format:]Date, Days[, Calendar, Calendar Event])
Parameters
-
SUB_DAYS
Subtracts a number of days from a specified date -
Date
Specifies the date in YYMMDD or YYYYMMDD format
Note: the date format applies to both the date you specify, and the date that the script function returns.
Format: script literal or script variable
(Optional) To use a different format, enter the desired date format followed by a separator (: or ;) and the date. -
Days
Number of days to subtract from the date
Format: script literal, number without quotation marks or script variable
Tip: Specify 0 days to validate a date against a Calendar object. If the date is valid according to the Calendar, the script function returns the specified date. If the date is not valid, the script function returns the previous valid date based on calendar conditions. -
Calendar
(Optional) Name of a Calendar object
If you specify a Calendar object, the calculation only takes days into account that are defined in Calendar Events in the Calendar object.
Format:AE name, script literal or script variable -
Calendar Event
(Optional) Name of a Calendar Event, if you specify a Calendar object
Format:AE name, script literal or script variable
Return Codes
This script function has the following return codes:
- 0
No days are assigned to the Calendar Event, or the calculated date lies outside of 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. The date is in the default YYMMDD format. The script prints the result (000330) in the activation report.
:SET &DATE# = SUB_DAYS("000401", 2)
:PRINT &DATE#
The following example lets a user define how long to store something. The script assigns the current date to a script variable, and uses a :READ statement to query the user about the number of days. The SUB_DAYS function subtracts the number provided by the user 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 and subtracts two days. The current date is not in the default date format. The special date format is specified in the parameters of the SUB_DAYS function.
:SET &CURDATE# = SYS_DATE("DD.MM.YY")
:SET &PWRKDAY# = SUB_DAYS("DD.MM.YY:&CURDATE#", 2)
See also: