Conversion of 2-Digit Years to 4-Digit Years or Centuries

When you are moving or comparing 2-digit years to 4-digit years or centuries, or comparing 4-digit years or centuries to 2-digit years, ILE COBOL first converts the 2-digit year using a windowing algorithm. The default windowing algorithm used is as follows:
  • If a 2-digit year is moved to a 4-digit year, the century (1st 2 digits of the year) are chosen as follows:
    • If the 2-digit year is greater than or equal to 40, the century used is 1900. In other words, 19 becomes the first 2 digits of the 4-digit year.
    • If the 2-digit year is less than 40, the century used is 2000. In other words, 20 becomes the first 2 digits of the 4-digit year.
  • If a data item with a 4-digit year or century is moved to a 2-digit year, the first 2 digits of the year (the century) are truncated. If later, the date is modified and that 2-digit year is moved back to a 4-digit year, then the algorithm just described for a 2-digit to 4-digit year move is used and inaccuracy can result. The programmer must ensure that when these types of moves are made, that inaccuracy does not result. In other words, if there is a chance that inaccuracy can result, just move 2-digit years to 2-digit years and 4-digit years to 4-digit years.
Note: When an alphanumeric data item containing a date is moved to a date-time data item, no checking or conversion is done. The programmer must ensure that the alphanumeric date being moved is in the correct format.
To show you how this works, three date moves are done in this program:
ID DIVISION.
PROGRAM-ID. datmoves.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SPECIAL-NAMES.
     FORMAT DATE IS '%m/%d/%y'.
DATA DIVISION.
WORKING-STORAGE SECTION.
77  date1  format date Value '07/12/39'.
77  date2  format date '@Y/%m/%d'.
77  date3  format date '%y/%m/%d'.
01  ALPHA_USA_S    PIC X(08).
PROCEDURE DIVISION.
PARA1.
     move date1 to date2.  1 
     display "date2 =" date2.
*
     move date2 to date3.  2 
     display "date3 =" date3.
*
     move FUNCTION ADD-DURATION (date3 YEARS 1) to date2.  3 
     display "date2 =" date2.
The output from this program is:
 date2 =2039/07/12
 date3 =39/07/12
 date2 =1940/07/12
In move  1 , date1 (containing the value 07/12/39) is moved to date2. Because date1 contains a 2-digit year that is less than 40, and it is moved to date2, which has a 4-digit year, the century used is 2000 and the 4-digit year becomes 2039.

In move  2 , a 4-digit year is moved to a 2-digit year, and the century (1st 2 digits of the year) is just truncated.

In move  3 , a year is added to date3 and it is then moved back to a 4-digit year. Because the year that was added moved the 2-digit year of the date out of the 21st century, the date becomes a 20th century date and is inaccurate. This move shows you how the windowing algorithm works, and how inaccuracies can result when moving dates between 4-digit and 2-digit year formats.