Date Data Type
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, temporarily changed by /SET and /RESTORE directives, and individually set by the definition specification keyword DATE or DATFMT.
- From the DATE or DATFMT keyword specified on the definition specification
- From the most recent /SET directive containing a DATFMT keyword that has not been restored by a /RESTORE directive.
- From the DATFMT keyword specified on the control specification
- *ISO
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 1 lists the RPG-defined formats for date data and their separators.
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 2 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 3 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 |
Note:
|