FIRST_OF_PERIOD

Use the FIRST_OF_PERIOD script function to return the first day of the period for a specified date.The period can be a year, quarter, month or week. The script function lets you specify the date format for the returned date. Optionally specify a Calendar Event to consider for the calculation.

Syntax

FIRST_OF_PERIOD ([DateFormat:]Date, PeriodFormat[, OutputFormat[, Calendar, Calendar Event]])

Parameters

Important! Include all commas when you specify a Calendar object and Calendar Event, even if you omit the OutputFormat parameter.

Return Codes

The script function has the following return values:

Note: If you specify a Calendar object and Calendar Event, the 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 specified date format (example: 0000-00-00).

Tip: Use the :ON_ERROR script statement to define action to take when an error occurs. For more information, see Script Elements for Error Handling.

Examples

These examples return the date of the first day of a period, given a particular date, and print the result in the activation report.

March 29, 2000 was a Wednesday. The following script specifies a period format (WW) that defines Monday as the first day of the week.

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

Line in the activation report:

2019-03-28 13:38:28 - U00020408 27.03.00

The following script uses the WS period format to define that the week starts with Sunday. The example uses the same date as in the previous example. In this example, the script specifies the date format because the date is provided in a different format than the default.

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

Line in the activation report:

2019-03-28 13:51:02 - U00020408 26.03.00

The following example assumes you have a Calendar object called READINESS that contains an Event (WEEKDAY) which includes only weekdays, not weekends. The script returns the first weekday of the quarter that the specified date lies in.

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

Line in the activation report:

2019-03-28 13:51:02 - U00020408 01.01.19

See also:

seealso

Script Date and Time Functions

Date, Time and Period Formats in Scripts