For Developers

Unix Timestamp in COBOL

How to get the current date and time in COBOL, and work with it — still a live question, since COBOL remains in production in banking, insurance, and government mainframe systems processing trillions of dollars in transactions today.

IDENTIFICATION DIVISION.
PROGRAM-ID. GETDATE.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-DATETIME.
   05 WS-YEAR    PIC 9(4).
   05 WS-MONTH   PIC 9(2).
   05 WS-DAY     PIC 9(2).
PROCEDURE DIVISION.
    MOVE FUNCTION CURRENT-DATE TO WS-DATETIME.
* COBOL has no native Unix-epoch concept at all. FUNCTION CURRENT-DATE
* returns a 21-character string: YYYYMMDDHHMMSSss+HHMM (date, time,
* hundredths of a second, and UTC offset) - not a numeric timestamp.
* Converting that string to something epoch-like is entirely manual,
* usually via FUNCTION INTEGER-OF-DATE for day-number arithmetic.
01 WS-DAYS PIC 9(7).
* FUNCTION INTEGER-OF-DATE converts a YYYYMMDD-format date into an
* integer day count usable for date arithmetic (differences, additions) -
* the closest COBOL equivalent to epoch-style math, though it counts
* days, not seconds, and uses its own reference point, not 1970.
MOVE FUNCTION INTEGER-OF-DATE(20250615) TO WS-DAYS.

The COBOL-specific pitfall

COBOL predates Unix time by over a decade and has no concept of a Unix epoch built into the language at all — FUNCTION CURRENT-DATE returns a fixed-format string, and date arithmetic is normally done through FUNCTION INTEGER-OF-DATE/FUNCTION DATE-OF-INTEGER, which convert to and from a day-count integer using COBOL's own internal reference point, not 1970-01-01. Any system that needs to exchange timestamps between a COBOL mainframe and a modern Unix-timestamp-based service has to bridge these two entirely different date representations explicitly — there's no shortcut, and it's a genuinely common integration point in banks and insurers still running COBOL cores alongside newer systems.

Have a timestamp right now?

Paste it into the Timestamp ⇄ Date Converter to check it instantly, in any timezone, without writing any code. Working across several languages on the same project? The full Epoch Time in Programming Languages guide has all of them side by side for quick comparison.

Related

Related tools & reading