The external format of a date is the format in which a date is displayed, the
format of a literal date in the source program, and the format in which a date
is input to the compiled program. It is specified by an optional clause in
the Special-names paragraph.
ENVIRONMENT DIVISION.
SPECIAL-NAMES.
[ DATE IS |"S-"|"E-"|"A-"| ]
where: S Sequential: ccyy-mm-dd
E European: dd-mm-ccyy
A American: mm-dd-ccyy
- any character except a space or a digit.
The default format is "S-".
A literal value in the source program or a value input on the screen to a compiled program may have both the day and the month zero suppressed. In addition, if the century is omitted, the century of the current system date is used instead.
A date field is defined in the Data Division as follows.
DATA DIVISION.
lvl-no dataname [USAGE IS] DATE
[ VALUE IS |date-lit|ZERO ] .
A date is always stored in a four character field; the PIC X(4) is not
necessary in the definition. A null date is defined as ZERO, is stored as a
LOW-VALUES field, and is displayed by the program as spaces.
A literal date must be enclosed in quotes.
PROCEDURE DIVISION.
The following special actions are available in the Procedure Division with
date fields.
MOVE date-item TO numeric-item
The numeric item will be set to the day of the week, 1 to 7 representing
Sunday to Saturday respectively, with zero representing a null date.
MOVE date-item TO display-item
Converts the date to the defined external format in the display-item.
MOVE display-item TO date-item
De-edits the display-item and stores the derived date in the date-item.
If display-item does not contain a valid date, date-item is set to low-values.
ADD number TO date-item
Adds a number of days to the date.
SUBTRACT number FROM date-item
Subtracts a number of days from the date.
SUBTRACT date-item-1 FROM date-item-2 GIVING binary-item
Calculates the difference in days between the two dates and stores the
result in binary-item, which must be defined as a binary integer item.
ADD and SUBTRACT statements are valid only for dates from 1901 to 2099 inclusive. Any other date will return a date or a value of zero.
Date Validation
There is no specific statement to validate a date. However, adding a number
to a date always returns a valid date regardless of the validity of the
original date. Thus, a date may be validated conveniently with the following
method:
MOVE ZERO TO null-count
MOVE date-to-validate TO check-date
ADD null-count TO check-date
IF check-date NOT = date-to-validate
GO TO date-error
.
See also:
ACCEPT date-field FROM DATE
SET DATE TO date-field