LAST_OF_PERIOD
Use the LAST_OF_PERIOD script function to determine the last day of the period to which a specified date belongs. The returned value is a date.
Tip: Use the :ON_ERROR script statement to define an action in case of an error. For more information, see Script Elements for Error Handling.
Syntax
LAST_OF_PERIOD ([Date Format:]Date, Period Format[, Output Format[, Calendar, Calendar Event]])
Parameters
| Parameter | Description | Format | Allowed Values |
|---|---|---|---|
| Date |
Define the date from which the period calculation should be performed. |
n.a. | n.a. |
| Period Format | Defines the type of period, such as a year, quarter, month, or week. For details, see Date, Time and Period Formats in Scripts. | Script literal or script variable |
|
| Output Format | (Optional) Format guidelines for the determined date. You must explicitly include commas if this parameter is omitted but Calendar and Calendar Event parameters are defined. | AE name, script literal, or script variable | Default: YYMMDD |
| Calendar | (Optional) Name of the Calendar object to be taken into account for the ending period. When used with Calendar Event, this function returns the correct calendar day of the period. If no valid calendar day exists for the period, a zero date is returned (e.g., 0000-00-00). | AE name, script literal, or script variable | n.a. |
| Calendar Event | (Optional) Name of the Calendar Event to be taken into account for the ending period. When used with Calendar, this function returns the correct calendar day of the period. If no valid calendar day exists for the period, a zero date is returned (e.g., 0000-00-00). | AE name, script literal, or script variable | n.a. |
Return Codes
The script function returns the date of the period end in the specified format. Alternatively, it can fail with the following runtime errors:
- 20327: The Calendar object does not exist.
- 20328: The Calendar Event does not exist in the Calendar object.
- 20456: The Calendar Event does not include the end date of the period.
Examples
The first example determines the last day of the week for 03/29/2022. The result 03.04.22 (Sunday) is output in the activation report:
:SET &DATE# = LAST_OF_PERIOD("000329", "WW", "DD.MM.YY")
:PRINT &DATE#
With the special period format "WS", the date 02.04.22 (Saturday) is output in the activation report:
:SET &DATE# = LAST_OF_PERIOD("DD.MM.YY:29.03.00", "WS", "DD.MM.YY")
:PRINT &DATE#
In the third example, the last calendar day of a quarter is determined. The guidelines of an output format are not taken into account:
:SET &DATE# = LAST_OF_PERIOD("000329", "Q",, READINESS, WEEKDAY)
:PRINT &DATE#
See also: