Key Takeaways: Date and Time Processing
-
Y2K taught permanent lessons: Always use 4-digit years, always validate dates, always test boundary conditions. Date windowing is still in production — know its expiration date.
-
Never subtract YYYYMMDD dates directly. Use
FUNCTION INTEGER-OF-DATEto convert to integer day numbers, perform arithmetic on the integers, and useFUNCTION DATE-OF-INTEGERto convert back. This handles all calendar complexities automatically. -
FUNCTION CURRENT-DATE returns 21 characters: 8 date (YYYYMMDD) + 8 time (HHMMSScc) + 5 GMT offset (sHHMM). Parse it into a structured group item for easy access.
-
Date validation is mandatory before any date arithmetic. INTEGER-OF-DATE abends on invalid dates. Validate: numeric check, year range, month range, day range with month/day/leap-year logic.
-
The leap year rule has three parts: Divisible by 4 (yes), EXCEPT divisible by 100 (no), EXCEPT divisible by 400 (yes). 2000 was a leap year; 1900 was not.
-
Aging calculations use date subtraction to assign items to buckets (Current, 30, 60, 90, 120+ days). Use the same calculation everywhere to avoid inconsistencies.
-
Business day calculations combine day-of-week determination (INTEGER-OF-DATE with MOD) and holiday table lookups (SEARCH ALL on sorted dates).
-
Timezone handling uses the GMT offset from CURRENT-DATE, with careful handling of day-boundary crossings near midnight.
-
Language Environment date services (CEECBLDY, CEEDATM) provide formatted output and flexible input parsing on z/OS, complementing the intrinsic functions.
-
One date module, used everywhere. Duplicate date logic guarantees inconsistency. Build a centralized date utility and call it from every program that processes dates.