COBOL provides intrinsic functions for date and time: getting the current date and time (CURRENT-DATE), converting between dates and integers for arithmetic (INTEGER-OF-DATE, DATE-OF-INTEGER), and related functions. These help you avoid hand-written date logic for month boundaries and leap years. This page explains the main date-time functions and how to use them.
Date-time functions are helpers that answer questions like "what is today?" (CURRENT-DATE) or "what date is 30 days from this date?" (INTEGER-OF-DATE, add 30, DATE-OF-INTEGER). Instead of you counting days and months, the function does it. You give it a date (or nothing for "now") and get back a value you can store or use in calculations.
| Function | Arguments | Returns | Typical use |
|---|---|---|---|
| CURRENT-DATE | None | Alphanumeric (e.g. 21 chars) | Get current date/time; substring for YYYYMMDD or HHMMSS |
| INTEGER-OF-DATE | Date (YYYYMMDD format) | Integer (day number) | Convert date to integer for arithmetic |
| DATE-OF-INTEGER | Integer (day number) | Date (YYYYMMDD) | Convert back to date after arithmetic |
| DAY-OF-INTEGER | Integer | Integer (day of week or similar) | Day-of-week from day number (implementation-dependent) |
| WHEN-COMPILED | None | Compilation timestamp | Version or build identification |
FUNCTION CURRENT-DATE takes no arguments and returns the current date and time. The return format is implementation-defined; often it is a 21-character string where positions 1–4 are year, 5–6 month, 7–8 day, 9–10 hour, 11–12 minute, 13–14 second, and the rest may be hundredths and timezone. Extract the date with reference modification: MOVE FUNCTION CURRENT-DATE(1:8) TO WS-YYYYMMDD gives you an 8-character date. Extract time with (9:6) for HHMMSS.
1234567801 WS-DATE-TIME PIC X(21). 01 WS-YYYYMMDD PIC X(8). 01 WS-HHMMSS PIC X(6). MOVE FUNCTION CURRENT-DATE TO WS-DATE-TIME *> Extract date (positions 1-8) and time (9-14 or 9-6 depending on format) MOVE WS-DATE-TIME(1:8) TO WS-YYYYMMDD MOVE WS-DATE-TIME(9:6) TO WS-HHMMSS
INTEGER-OF-DATE converts a date (typically in YYYYMMDD or similar format) to an integer that represents that date (e.g. days since a base date). DATE-OF-INTEGER converts that integer back to a date. The base date and exact argument/return formats are defined by your COBOL implementation. Use these for date arithmetic: convert to integer, add or subtract days, convert back. This correctly handles month and year boundaries and leap years.
12345678*> Add 30 days to WS-START-DATE (PIC 9(8) YYYYMMDD) 01 WS-START-DATE PIC 9(8) VALUE 20240101. 01 WS-INT-DATE PIC S9(9). 01 WS-END-DATE PIC 9(8). COMPUTE WS-INT-DATE = FUNCTION INTEGER-OF-DATE(WS-START-DATE) + 30 MOVE FUNCTION DATE-OF-INTEGER(WS-INT-DATE) TO WS-END-DATE *> WS-END-DATE now holds the date 30 days later
1. How do you get the current date and time in COBOL?
2. To add 7 days to a date, a common approach is: