CL Command Reference - CVTDAT
CL Command List > CVTDAT Reference
Description:
The Convert Date (CVTDAT) command converts the format of a date value from one format to another, without changing its value. The command ignores any date separators used in the old format, but if separators are included in the converted result, a separator character can be specified on the command.
Only valid dates can be converted. If either the from-format or the to-format use only 2 digits to specify the year (for example, *MDY, *DMY, *YMD, or *JUL), valid dates are in the range of January 1, 1940, to December 31, 2039. Otherwise, valid dates are in the range of August 24, 1928, to May 9, 2071. If the year is specified with only 2 digits, years in the range of 40 to 99 are assumed to be 1940 to 1999; years in the range 00 to 39 are assumed to be 2000 to 2039. The command works in conjunction with the QLEAPADJ system value.
Restrictions: This command is valid only within a CL procedure.
Examples:
Example 1: Converting to DMY Format
DCL VAR(&DATE) TYPE(*CHAR) LEN(8)
:
CVTDAT DATE(¡¯12-24-88¡¯) TOVAR(&DATE) TOFMT(*DMY)
This command converts the date 12-24-88, which is in the MDY format. Because the FROMFMT parameter was not specified, its default, *JOB, indicates that the job attribute DATFMT contains the MDY format. The date is converted to the DMY format, and the separator character specified in the job attribute DATSEP is inserted. If DATSEP contains a slash, the converted result is 24/12/88.
Example 2: Converting to Format Specified by Job Attribute
DCL &PAYDAY *CHAR 6
DCL &NEWPDAY *CHAR 6
:
CVTDAT DATE(&PAYDAY) TOVAR(&NEWPDAY)
FROMFMT(*YMD) TOSEP(*NONE)
This command converts the format of the date stored in &PAYDAY from year, month, day to the format specified by the job attribute DATFMT. If, for example, DATFMT contains the MDY format, the format of the converted date is month, day, and year. The converted date is stored in the variable &NEWPDAY. Because &NEWPDAY was declared as a 6-character variable, TOSEP(*NONE) is required; the converted result cannot include separator characters.
Example 3: Converting to CYMD format
DCL &NEWDAY1 *CHAR 7
DCL &NEWDAY2 *CHAR 7
:
CVTDAT DATE(¡¯01/24/1939¡¯) TOVAR(&NEWDAY1)
FROMFMT(*MDYY) TOFMT(*CYMD) TOSEP(*NONE)
CVTDAT DATE(¡¯01/24/39¡¯) TOVAR(&NEWDAY2)
FROMFMT(*MDY) TOFMT(*CYMD) TOSEP(*NONE)
The first CVTDAT command converts the date specified on the DATE parameter from the month, day, 4-digit year format to the century, year, month, day format. Because the year was specified with 4 digits and the first 2 digits are ¡å19¡å, the century digit is set to ¡å0¡å, so the value of ¡åNEWDAY1 is ¡å0390124¡å.
The second CVTDAT command converts the date specified on the DATE parameter from the month, day, year format to the century, year, month, day format. Because the year was specified with only 2 digits and the year is less than 40, the century digit is set to ¡å1¡å, so the value of ¡åNEWDAY2 is ¡å1390124¡å.