ILE COBOL Programmer's Guide


Specifying Date, Time, and Timestamp Data Types

Items of COBOL class date-time, include date, time, and timestamp items. These items are declared with the FORMAT clause of a data description entry. For example:

01  group-item.
    05 date1 FORMAT DATE "%m/%d/@Y".
    05 date2 FORMAT DATE. 

For items of class date-time the FORMAT clause is used in place of a PICTURE clause. In the example above, after the keyword FORMAT the keyword DATE declares an item of category date. After the keyword date a format literal describes the format of the date data item. In the case of data item date1 the %m stands for months, %d for days, and the @Y for year (including a 2-digit century). The % and @ character begin a specifier. The three specifiers shown here are part of a set of specifiers documented in the WebSphere Development Studio: ILE COBOL Reference .

The other date data item, date2, has no format literal explicitly specified; however, a default date format can be specified in the SPECIAL-NAMES paragraph. An example is shown below:

SPECIAL-NAMES.  FORMAT OF DATE IS "@C:%y:%j".

If the above SPECIAL-NAMES paragraph had been specified in the same program as the data item, date2, its date format would have been @C:%y:%j. On the other hand, if a SPECIAL-NAMES paragraph did not exist, the format of the date item would default to ISO. An ISO date has the format @Y-%m-%d.

By default when COPY DDS declares items of class date-time it generates a PICTURE clause for an alphanumeric item. In order to change the PICTURE clause into a FORMAT clause, several new CVTOPT parameter values have been defined. These are:

When *DATE has been specified, any DDS date data types are converted to COBOL date items; in other words, a FORMAT clause is generated instead of a PICTURE clause.

In DDS to specify the format of a date field, the DATFMT keyword can be specified. The DATFMT keyword can also be specified on zoned, packed, and character fields. For these types of fields, COPY DDS would normally generate a PICTURE clause for a numeric zoned, numeric packed, and alphanumeric data item, respectively. You can force COPY DDS to generate a FORMAT clause for these items by specifying the *CVTTODATE value of the CVTOPT parameter.

For a list of the DATFMT parameters allowed for zoned, packed, and character DDS fields, and their equivalent ILE COBOL format that is generated from COPY DDS when the CVTOPT(*CVTTODATE) conversion parameter is specified, refer to Class Date-Time and Working with Date-Time Data Types.

For moves and comparisons involving a mixture of 4-digit and 2-digit dates, ILE COBOL uses a default windowing algorithm with a base century of 1900 and a base year of 40. Because inaccuracies can result, it may be necessary to override the default window. For more information about the ILE COBOL windowing algorithm and how to override it, refer to Conversion of 2-Digit Years to 4-Digit Years or Centuries.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]