Syntax
DATECONVERT date_variable [ {+ | -}date_varible ] FORMAT format [ variable FORMAT format | EDITONLY ] [GS status]
Parameters
DateConvert can be abbreviated as DC.
date_variable
The input date. If it is a number-primitive, then its format must be one of the number formats listed in DateConvert Variable Format.
{+ or -} date_variable
The offset, measured in days, of the result date from the input date.
FORMAT format (first)
FORMAT can be abbreviated as FMT. The format of the preceding input date. The format parameter must be one of the formats listed in DateConvert Variable Format.
variable
A string-primitive or number-primitive variable to receive the result. If it is a number-primitive, then its format must be one of the number formats listed in DateConvert Variable Format.
FORMAT format (second)
FORMAT can be abbreviated as FMT. The format of the preceding result variable. The format parameter must be one the formats listed in DateConvert Variable Format.
After executing with this clause, the Glb.DC_ built-in segment attributes are undefined.
EDITONLY
Validates the date variable.
After executing with this command option, the Glb.DC_ built-in segment attributes are undefined.
GS status
Indicates an invalid date using the specified variable.
Description
The complex form of the DateConvert logic command converts the value of a variable, storing the result in a series of built-in segment attributes with the prefix Glb.DC_, or in a single variable in a specified format.
The conversion is based on a base date defined by the Glb.Base, Glb.Century, and Glb.Century_Start built-in segment attributes. .
The complex form of the DateConvert logic command can be used to:
Convert the value of a variable in a specified format, storing the result in a series of Glb.DC_ built-in segment attributes.
These built-in segment attributes are cleared before the DateConvert logic command is completed. Refer to Glb.DC_ Attributes for a list of the Glb.DC_ built-in segment attributes available after successful execution of the DateConvert logic command.
Modify the result, by adding or subtracting a number of days.
Convert the value of a variable in a specified format and store the result in another variable, also in a specified format. The remaining Glb.DC_ built-in segment attributes are undefined.
Validate the value of a variable, using the DateConvert EditOnly logic command variant. The Glb.DC_ built-in segment attributes are undefined, and Glb.Century is not set.
Set Glb.Century, if the segment's DC Sets Glb.Century property is set to true. If this property is not set, the Glb.Century built-in segment attribute is not automatically set, and the century is calculated using the Glb.Century_Start built-in segment attribute.
DateConvert logic statements in which the destination variable has the DAYNUM format do not set the Glb.Century or Glb.DC_ built-in segment attributes.
Note: Historic dates are not adjusted for past changes in the calendar.
Failure behavior
A date is invalid if:
It is a non-existent date. For example, 29 February 2100 is an invalid entry.
It is prior to the start of the Glb.Base year.
Note: The Glb.Century built-in segment attribute can be automatically set to ensure the validity of the date. Refer to DateConvert Base Date.
If the date is invalid, the Glb.Status built-in segment attribute is set to "*****". Use the GS command option to direct the result to a variable. Error testing should be used whenever the DateConvert logic command is invoked.
If the Glb.Status built-in segment attribute is set to "*****", the DateConvert logic command is still executed, but uses the current date. If the current date is invalid (for example, it is prior to the start of the base year), then January 1 of the base year is used as input.
Restrictions
The following restrictions apply to use of the complex form of the DateConvert logic command:
An input date of 0 is only valid in DAYNUM format. It is invalid in all other formats.
Handling of signed numbers in group variables by the DateConvert logic command depends on the compiler implementation. Number-primitive variables within a group variable should be unsigned.
The relative day number is the number of days after the base date (1/1/<base year>). Conversion of relative day number is limited to a maximum of 999999 days, starting from 1 January of the base year. The relative day number of January 1 of the base year is 0.
Numeric input is limited to a maximum length of 23 characters.
Examples
Example 1
This example converts the Prod.Ord_DayNum relative day number. The result is stored in the Glb.DC_ built-in segment attributes.
DateConvert Prod.Ord_DayNum Format DAYNUM
Example 2
This example converts the Tran_Date date, in YYMMDD format, into CCYY-MMM-DD format, and stores it in DB_Date.
DateConvert Tran_Date Format YYMMDD DB_Date Format CCYY-MMM-DD
Example 3
This example sets Glb.Century to 19 prior to converting Tran_Date, in YYMMDD format. The result is stored in the Glb.DC_ built-in segment attributes.
Glb.Century := 19 DateConvert Tran_Date Format YYMMDD
Example 4
This example converts the date, 45 days after OrderDay, into DAYNUM format. The result is stored in the Glb.DC_ built-in segment attributes.
DateConvert OrderDay + 45 Format DAYNUM
Example 5
This example converts the date, Num_Days before Glb.Today, into YYMMMDD format. The result is stored in the Glb.DC_ built-in segment attributes.
Note: If Num_Days is a signed value, its sign is ignored.
DateConvert Glb.Today – Num_Days Format YYMMMDD
Example 6
This example validates Tran_Date in YYMMDD format. There is no output conversion.
DateConvert Tran_Date Format YYMMDD EditOnly
DateConvert Base Date
The conversion performed by the DateConvert complex form is based upon a base date defined by the Glb.Base, Glb.Century, and Glb.Century_Start built-in segment attributes.
Glb.Base and Glb.Century_Start
Set the Glb.Century_Start built-in segment attribute using the segment's Century Start Year property. If this property is not set, the Glb.Century_Start built-in segment attribute is set using the Glb.Base built-in segment attribute.
Set the Glb.Base built-in segment attribute using the segment's BaseYear property. The valid range is 1 through 9999. If this property is not set, the Glb.Base built-in segment attribute is set to 1957.
Glb.Century
The Glb.Century built-in segment attribute is set if the input date of the DateConvert logic command does not contain the century (it is a six-digit date). This is required if the century of the input date is different from the default century.
The Glb.Century built-in segment attribute is set to the next century if the year is less than the Glb.Century_Start built-in segment attribute, and either of the following conditions is true:
The Glb.Century built-in segment attribute value is zero (it is not set).
The Glb.Century built-in segment attribute value is the same as the Glb.Century_Start built-in segment attribute century.
The Glb.Century built-in segment attribute is reinitialized in the Construct method, which is normally, but not always, called for each transaction. To ensure consistent results, set the Glb.Century built-in segment attribute to zero before using the DateConvert logic command to deduce the century.
Restrictions
The current century, instead of the Glb.Century built-in segment attribute, is used for the Glb.Today, Glb.Todays_Date_Num, Glb.YYMMDD, and built-in segment attributes and Input_Date built-in ispec attribute (except if it is from a database record).
Example
In this example, the Glb.Century_Start built-in segment attribute is set to 1957 (the same as the Glb.Base built-in segment attribute value) and the Glb.Century built-in segment attribute value is set to 0 (or 19).
The years 57 through 99 represent 1957 through 1999.
The years 00 through 56 represent 2000 through 2056.
If a DateConvert logic command is invoked with a year 50 followed by years of 60 and 70, and the segment's DC Sets Glb.Century property is set to true, the Glb.Century built-in segment attribute is set to 20 (since 1950 is prior to the value of Glb.Century_Start), and the years are interpreted as 2050, 2060, and 2070.
DateConvert Variable Format
The following table lists valid formats specified with the Format command parameter of the DateConvert complex form.
Note: Examples assume a Glb.Base value of 1957.
Format | Length | Primitive | Layout | Example |
---|---|---|---|---|
DAYNUM | 6 | Number | nnnnnn | 15788 |
UK-ALPHA | 25 | String | DDbMMMMMMbCCYY | 23 MARCH 2000 |
US-ALPHA | 25 | String | MMMMMMbDDbCCYY | MARCH 23 2000 |
IN-ALPHA | 25 | String | CCYYbMMMMMMbDD | 2000 MARCH 23 |
DD-MM-YY | 8 | String | DD/MM/YY | 23/03/00 |
DD-MM-CCYY | 10 | String | DD/MM/CCYY | 23/03/2000 |
DD-MMM-YY | 9 | String | DDbMMMbYY | 23 MAR 00 |
DD-MMM-CCYY | 11 | String | DDbMMMbCCYY | 23 MAR 2000 |
DDMMMYY | 7 | String | DDMMMYY | 23MAR00 |
DDMMMCCYY | 9 | String | DDMMMCCYY | 23MAR2000 |
DDMMYY | 6 | Number | DDMMYY | 230300 |
DDMMCCYY | 8 | Number | DDMMCCYY | 23032000 |
MM-DD-YY | 8 | String | MM/DD/YY | 03/23/00 |
MM-DD-CCYY | 10 | String | MM/DD/CCYY | 03/23/2000 |
MMDDYY | 6 | Number | MMDDYY | 032300 |
MMDDCCYY | 8 | Number | MMDDCCYY | 03232000 |
MMM-DD-YY | 9 | String | MMMbDDbYY | MAR 23 00 |
MMM-DD-CCYY | 11 | String | MMMbDDbCCYY | MAR 23 2000 |
MMMDDYY | 7 | String | MMMDDYY | MAR2300 |
MMMDDCCYY | 9 | String | MMMDDCCYY | MAR232000 |
YY-MM-DD | 8 | String | YY/MM/DD | 00/03/23 |
CCYY-MM-DD | 10 | String | CCYY/MM/DD | 2000/03/23 |
YY-MMM-DD | 9 | String | YYbMMMbDD | 00 MAR 23 |
CCYY-MMM-DD | 11 | String | CCYYbMMMbDD | 2000 MAR 23 |
YYDDD | 5 | Number | YYDDD | 00083 |
CCYYDDD | 7 | Number | CCYYDDD | 2000083 |
YYMMDD | 6 | Number | YYMMDD | 000323 |
CCYYMMDD | 8 | Number | CCYYMMDD | 20000323 |
YYMMMDD | 7 | String | YYMMMDD | 00MAR23 |
CCYYMMMDD | 9 | String | CCYYMMMDD | 2000MAR23 |
TODAY | 15 | String | (day name) | THURSDAY |
WEEKNO (result only) | 2 | Number | nn | 13 |