COBOL allows you to accept a number of data items from the operating system, including current date.
ACCEPT WS-YYMMDD FROM DATE.
This statement will return a six-digit date in the format of YYMMDD. The variable WS-YYMMDD must be defined in WORKING-STORAGE.
ACCEPT WS-CCYYMMDD FROM CENTURY-DATE.
This statement will return an eight-digit date in the format of CCYYMMDD. The variable WS-CCYYMMDD must be defined in WORKING-STORAGE.
COBOL provides some handy functions, and some of the most widely used are the date functions. Let say, for example, that you’re processing an invoice, and you need to determine the due date, which is always 30 days from the current date. You could use the following logic:
The COBOL function INTEGER-OF-DATE converts a Gregorian date to an integer. Conversely, the function DATE-OF-INTEGER converts an integer to a Gregorian date.
Functions are handy tools, and are exceedingly easier than the methods we previously used that required copious amounts of code to convert a Gregorian date to a Julian date and vice versa. You’ll do yourself a huge favor if you learn the COBOL functions!