Automation Engine Script Guide > Ordered by Function > Date and Time > FIRST_OF_PERIOD

FIRST_OF_PERIOD

Script Function: Determines the first day of the period for a specified date

Syntax

FIRST_OF_PERIOD (Date, Period Format, [Output Format, [[Calendar], [Calendar Keyword]])

Syntax

Description/Format

Date

Indication of a date in the format "YYMMDD" or "YYYYMMDD".

Format: script literal or script variable

It is also possible to specify a different date format. Do so by entering the required date format, then enter a separator (: or ;) and afterwards the date. Indicating a date format is optional.

Period Format

Format guidelines for the Period

Output Format

Format guidelines for the determined date
Format: script literal or script variable
Default: YYMMDD  

Calendar

Name of the calendar which should be taken into account  for the period beginning
Format: AE name, script literal or script variable

Calendar Keyword

Name of the calendar keyword which should be taken into account for the period beginning
Format: AE name, script literal or script variable  


Return codes

Date of period start in the specified format
"20327" - The Calendar object does not exist
"20328" - The calendar keyword does not exist in the Calendar object
"20456" - The calendar keyword does not include the period's starting date

Comments

This script function determines the first day of the period to which a specified date belongs. The returned value is a date.

The script function is given a date. Optionally, you may specify a particular date format. The default date formats to be used are "YYMMDD" or "YYYYMMDD". A colon or semicolon may be used as a separator between Date Format and Date.

With Period Format, the type of period (year, quarter, month or week) is defined.
Note:
There is a special period format "WS" for this function. That way Sunday is always taken as the first day of the week. "WW", however, takes Monday as the first day of the week.

Output Format is optional. If Output Format is not used, the script function returns the default format "YYMMDD" as the date. Please note: Commas are to be used when Output Format is not used but Calendar and Calendar Keyword are specified.

If Calendar and Calendar Keyword are used, this script function returns the correct calendar day of the period. If there is no valid calendar day for this period, the result is a zero date in the respective date format (e.g.: 0000-00-00).

The script statement :ON_ERROR may be used to determine the reaction to this error which can then be analyzed with the script functions for error handling. Script processing is continued but can also be canceled if required.

Examples

The first example determines the day of the week as 03/29/2000. As a result, 27.03.00 (Monday) is output in the activation protocol.

:SET &DATE# = FIRST_OF_PERIOD ("000329","WW","DD.MM.YY")
:
PRINT &DATE#

With the special period format "WS", 26.03.00 (Sunday) is output in the activation protocol.

:SET &DATE# = FIRST_OF_PERIOD ("DD.MM.YY:29.03.00","WS","DD.MM.YY")
:
PRINT &DATE#

In the third example, the first correct calendar day of a quarter is determined. The guidelines of an output format are not taken into account.

:SET &DATE# = FIRST_OF_PERIOD ("000329", "Q", , READINESS, WEEKDAY)
:
PRINT &DATE#

 

See also:

Script element Description

LAST_OF_PERIOD

Determines the last day of period of a specified date

:ON_ERROR

Determines the reaction to certain errors and messages of script elements

Script Elements - Date and Time

Date, Time and Period Formats

About Scripts
Script Elements - Alphabetical Listing

Script Elements - Ordered by Function