Date fields have a predetermined size and format. They can be defined on the definition specification. Leading and trailing zeros are required for all date data.
Date constants or variables used in comparisons or assignments do not have to be in the same format or use the same separators. Also, dates used for I/O operations such as input fields, output fields or key fields are also converted (if required) to the necessary format for the operation.
The default internal format for date variables is *ISO. This default internal format can be overridden globally by the control specification keyword DATFMT and individually by the definition specification keyword DATFMT.
The hierarchy used when determining the internal date format and separator for a date field is
There are three kinds of date data formats, depending on the range of years that can be represented. This leads to the possibility of a date overflow or underflow condition occurring when the result of an operation is a date outside the valid range for the target field. The formats and ranges are as follows:
Number of Digits in Year | Range of Years |
---|---|
2 (*YMD, *DMY, *MDY, *JUL) | 1940 to 2039 |
3 (*CYMD, *CDMY, *CMDY) | 1900 to 2899 |
4 (*ISO, *USA, *EUR, *JIS, *LONGJUL) | 0001 to 9999 |
Table 33 lists the RPG-defined formats for date data and their separators.
For examples on how to code date fields, see the examples in:
Format Name | Description | Format (Default Separator) | Valid Separators | Length | Example |
---|---|---|---|---|---|
2-Digit Year Formats | |||||
*MDY | Month/Day/Year | mm/dd/yy | / - . , '&' | 8 | 01/15/96 |
*DMY | Day/Month/Year | dd/mm/yy | / - . , '&' | 8 | 15/01/96 |
*YMD | Year/Month/Day | yy/mm/dd | / - . , '&' | 8 | 96/01/15 |
*JUL | Julian | yy/ddd | / - . , '&' | 6 | 96/015 |
4-Digit Year Formats | |||||
*ISO | International Standards Organization | yyyy-mm-dd | - | 10 | 1996-01-15 |
*USA | IBM USA Standard | mm/dd/yyyy | / | 10 | 01/15/1996 |
*EUR | IBM European Standard | dd.mm.yyyy | . | 10 | 15.01.1996 |
*JIS | Japanese Industrial Standard Christian Era | yyyy-mm-dd | - | 10 | 1996-01-15 |
Table 34 lists the *LOVAL, *HIVAL, and default values for all the RPG-defined date formats.
Format name | Description | *LOVAL | *HIVAL | Default Value |
---|---|---|---|---|
2-Digit Year Formats | ||||
*MDY | Month/Day/Year | 01/01/40 | 12/31/39 | 01/01/40 |
*DMY | Day/Month/Year | 01/01/40 | 31/12/39 | 01/01/40 |
*YMD | Year/Month/Day | 40/01/01 | 39/12/31 | 40/01/01 |
*JUL | Julian | 40/001 | 39/365 | 40/001 |
4-Digit Year Formats | ||||
*ISO | International Standards Organization | 0001-01-01 | 9999-12-31 | 0001-01-01 |
*USA | IBM USA Standard | 01/01/0001 | 12/31/9999 | 01/01/0001 |
*EUR | IBM European Standard | 01.01.0001 | 31.12.9999 | 01.01.0001 |
*JIS | Japanese Industrial Standard Christian Era | 0001-01-01 | 9999-12-31 | 0001-01-01 |
Several formats are also supported for fields used by the MOVE, MOVEL, and TEST operations only. This support is provided for compatibility with externally defined values that are already in a 3-digit year format and the 4-digit year *LONGJUL format. It also applies to the 2-digit year formats when *JOBRUN is specified.
*JOBRUN should be used when the field which it is describing is known to have the attributes from the job. For instance, a 12-digit numeric result of a TIME operation will be in the job date format.
Table 35 lists the valid externally defined date formats that can be used in Factor 1 of a MOVE, MOVEL, and TEST operation.
Format Name | Description | Format (Default Separator) | Valid Separators | Length | Example |
---|---|---|---|---|---|
2-Digit Year Formats | |||||
*JOBRUN1 | Determined at runtime from the DATFMT, or DATSEP job values. | ||||
3-Digit Year Formats2 | |||||
*CYMD | Century Year/Month/Day | cyy/mm/dd | / - . , '&' | 9 | 101/04/25 |
*CMDY | Century Month/Day/Year | cmm/dd/yy | / - . , '&' | 9 | 104/25/01 |
*CDMY | Century Day/Month/Year | cdd/mm/yy | / - . , '&' | 9 | 125/04/01 |
4-Digit Year Formats | |||||
*LONGJUL | Long Julian | yyyy/ddd | / - . , '&' | 8 | 2001/115 |
Notes:
|