Decision Guide: Portable System Date Retrieval in COBOL Using ACCEPT DATE
Learn how to use the COBOL ACCEPT DATE statement to get the system date across IBM Enterprise COBOL, GnuCOBOL, and Micro Focus, with format comparison, trade‑offs, and a portable code pattern.
19 May 2026, 15:34 UTC

Decision point
You need to embed system‑date retrieval in a COBOL program that must compile and run across IBM Enterprise COBOL, GnuCOBOL, and Micro Focus compilers. The ACCEPT DATE statement provides the date, but its output format is compiler‑dependent: IBM returns CCYYMMDD, GnuCOBOL returns ISO‑8601‑style strings, and Micro Focus uses a version‑dependent layout. This guide states the decision, compares options, explains trade‑offs, and shows a portable implementation you can validate.
Constraints and compiler landscape
Before writing ACCEPT DATE, three constraints shape the approach:
- Compiler vendor determines the string format and supported phrases.
- The TIME phrase is optional; not all compilers support TIMEZONE, and older versions may reject the clause entirely.
- In batch or automated jobs, repeated ACCEPT calls can serialize on the system clock, potentially stalling downstream automation.
| Compiler | DATE Format | TIME Phrase Support | QUERY NAME Support |
|---|---|---|---|
| IBM Enterprise COBOL | CCYYMMDD | Supported | Supported in some editions |
| GnuCOBOL | ISO (YYYY‑MM‑DD) | Supported | Not standard |
| Micro Focus | Version‑dependent (often CCYYMMDD) | Supported | Limited |
Trade‑offs
Choosing ACCEPT DATE means accepting format divergence. If your downstream system expects ISO‑8601, GnuCOBOL gives it directly; IBM requires a reformat step or a CONVERT routine. Conditional compilation (e.g., using $$ directives) can dispatch the right ACCEPT phrase per compiler, but adds source‑code complexity. Using the $DATE or $TIME environment variables as a fallback avoids compiler‑specific phrasing entirely, at the cost of making the program dependent on an external environment rather than the runtime clock.
Concrete implementation
IDENTIFICATION DIVISION.
PROGRAM-ID. GET-DATE.
DATA DIVISION.
WORKING-STORAGE SECTION.
DATE-LIT PIC X(10).
TIME-LIT PIC X(8).
PROCEDURE DIVISION.
ACCEPT DATE DATE-LIT.
*> IBM: CCYYMMDD; Gnu: ISO; MF: version‑dependent
DISPLAY 'System date: ' DATE-LIT.
ACCEPT TIME TIME-LIT.
DISPLAY 'System time: ' TIME-LIT.
END PROGRAM GET-DATE.
The snippet above exercises ACCEPT DATE and TIME in a minimal program. Format handling after retrieval is your responsibility; a common pattern is to reformat the string immediately after ACCEPT, or to read the value into a DATE‑TIME module that normalizes it for your environment.
Validation and checking results
To verify the output format without running the program on every compiler, compile and execute the test unit and compare its printed date string to the system’s $DATE (Linux/macOS) or DATE environment variable. Example command sequence (run from a shell with the compiled binary):
gnucobol -o get-date get-date.cob
./get-date
echo 'Expected ISO date: $DATE'
Required permissions: read/execute on the source and output directory. Meaningful placeholders: replace get-date.cob with your filename, $DATE with your platform’s variable name (e.g., %DATE% on Windows). Expected checks: the program’s DATE-LIT output should match or be translatable to the $DATE value within your locale’s format. Relevant risks: if $DATE is unset, the comparison yields empty strings, which may be misinterpreted as a format mismatch. Always run the binary on the target compiler first to observe the actual string layout before scripting automated checks.
Limitations
ACCEPT DATE’s format is not guaranteed across future compiler versions; IBM has introduced a CONFIGURE DATE FORMAT directive in recent releases that can alter the default. Multi‑threaded programs must serialize ACCEPT calls or risk reading a clock value changed by a concurrent thread. Older compilers (pre‑2010 Micro Focus, pre‑GnuCOBOL 2.0) may not support the TIME phrase at all, causing compilation errors if the clause is present. Additionally, mixing ACCEPT DATE with runtime environment variables that override the system clock (e.g., TZ environment variable) can produce unexpected string values, so validate the behavior in a non‑production run before deployment.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.