The GetDate procedure returns the relative date given a command and day of the week in words.
result-date GetDate( szCmd 20A Const Options(*NOPASS) szDay 10A Const Options(*NOPASS) baseDate D Const Options(*NOPASS) DATFMT(*ISO) |
These szCmd parameters, when specified, cause any other parameters to be ignored.
| Single szCmd Parameter | Description |
| Tomorrow | Return tomorrow's date |
| Yesterday | Return yesterday's date |
| Today | Return today's date. This is the default if no parameters are specified. |
These szCmd parameters, when specified, must be specified in conjunction with the day (szDay) parameter.
|
szCmds Requiring an szDay Parameter |
Description |
| Next | Return the next szDay'sdate |
| Previous | Return the previous szDay's date |
| First | Return the date of the first occurrence of szDay in the month of the date specified on the date parameter. |
| Last | Return the date of the last occurrence of szDay in the month of the date specified on the date parameter. |
| This | Return the date of the next szDay's date unless the date is already the same as szDay's, then it returns the same date. See examples below for more details. |
| First or 1 | Return the 1st date of the month for the szDay specified. |
| Second or 2 | Return the 2nd date of the month for the szDay specified. |
| Third or 3 | Return the 3rd date of the month for the szDay specified. |
| Fourth or 4 | Return the 4th date of the month for the szDay specified. |
| Fifth or 5 | Return the 5th date of the month for the szDay specified. |
| Count | Return the count of the number of times szDay occurs in the month specified for base date. |
| szDay Parameter Options | Description |
| Sunday | Return the date for the Sunday specified on the szCmd parameter. |
| Monday | Return the date for the Monday specified on the szCmd parameter. |
| Tuesday | Return the date for the Tuesday specified on the szCmd parameter. |
| Wednesday | Return the date for the Wednesday specified on the szCmd parameter. |
| Thursday | Return the date for the Thursday specified on the szCmd parameter. |
| Friday | Return the date for the Friday specified on the szCmd parameter. |
| Saturday | Return the date for the Saturday specified on the szCmd parameter. |
| Workday | Return the date for the relative Workday (Monday through Friday date) specified on the szCmd parameter. |
Only the first 3 characters of the szCmd and szDay parameter are interpreted. The remaining characters (if any) are ignored.
The szCmd and szDay parameters are not case sensitive.
The return value is the date of the relative day requested, or January 01, 0001 if an error occurs.
In the example that follows, a relative date is returned for the previous work day, next Wednesday, and the date for the 2nd Tuesday of the month of November 2004.
The final four GetDate() calls return the date for "next" Saturday and "this" Saturday respectively. These are identified in the examples as Group 2 and Group 3.
D dtNov S D INZ(D'2004-11-01')
D NextWorkDay S D
D WeekEnding S D
D NextWed S D
D ElectionDay S D
** Group 1
C eval nextWorkDay = GetDate('PREV':'WORKDAY')
C eval nextWed = GetDate('Next':'Wed')
C eval ElectionDay = GetDate('Second':'Tuesday': dtNOV)
** Group 2
C eval NextSat = GetDate('Next':'Saturday': D'2004-08-21')
C eval WeekEnding = GetDate('This':'Saturday': D'2004-08-21')
** Group 3
C eval NextSat2 = GetDate('Next':'Saturday': D'2004-08-20')
C eval WeekEnding2 = GetDate('This':'Saturday': D'2004-08-20')
In Group 2, the input date is also a Saturday date, which is what is being requested. TheGetDate('Next':'Saturday': D'2004-08-21') statement option returns the date of August 28, 2004. Whereas the GetDate('This':'Saturday': D'2004-08-21')statement returns a date of August 21, 2004. This is a subtle but important difference to understand. The "next" option always returns the next date, even if the input day matches the day being requested.
In Group 3, the input date is a Friday, August 20, 2004. In this situation both the "next" and "this" GetDate() statements return a date of Saturday, August 21, 2004.