Quiz: Date and Time Processing
Multiple Choice
1. How many characters does FUNCTION CURRENT-DATE return?
a) 8 b) 14 c) 21 d) 26
2. What is the correct way to compute the number of days between two dates in COBOL?
a) Subtract the YYYYMMDD values directly b) Use FUNCTION INTEGER-OF-DATE on both and subtract c) Use FUNCTION DATE-DIFF d) Use FUNCTION DAYS-BETWEEN
3. Which of the following years is NOT a leap year?
a) 2000 b) 2024 c) 1900 d) 2400
4. What was the primary Y2K remediation approach that provided a permanent fix?
a) Date windowing b) Date expansion c) Date compression d) Date elimination
5. In FUNCTION CURRENT-DATE, positions 17-21 represent:
a) The timezone name b) The daylight saving time flag c) The GMT offset (sign, hours, minutes) d) The day of the week
6. What does FUNCTION INTEGER-OF-DATE return?
a) The number of seconds since epoch b) The number of days since a base date c) The Julian day number d) The UNIX timestamp
7. What function converts an integer day number back to a YYYYMMDD date?
a) FUNCTION INTEGER-TO-DATE b) FUNCTION DATE-OF-INTEGER c) FUNCTION CONVERT-DATE d) FUNCTION FORMAT-DATE
8. Which approach correctly checks for a leap year?
a) Year divisible by 4 b) Year divisible by 4, except divisible by 100 c) Year divisible by 4, except divisible by 100, except divisible by 400 d) Year divisible by 4 and divisible by 100
9. What is the risk of calling FUNCTION INTEGER-OF-DATE with an invalid date?
a) Returns zero b) Returns -1 c) Causes a runtime abend d) Returns the nearest valid date
10. In date windowing with a pivot year of 50, how is a 2-digit year of "49" interpreted?
a) 1949 b) 2049 c) Ambiguous — depends on context d) Invalid
True or False
11. You can subtract two YYYYMMDD dates directly and get the correct number of days between them.
12. FUNCTION CURRENT-DATE includes timezone offset information.
13. February 29 is valid in the year 1900.
14. The COBOL 2002 standard formalized the requirement for 4-digit year fields.
15. IBM's CEECBLDY service uses the same epoch as FUNCTION INTEGER-OF-DATE.
Short Answer
16. Explain why simply subtracting 20240301 - 20240228 does NOT give you the correct number of days between March 1 and February 28, 2024. What is the correct approach?
17. Describe how to determine the day of the week for any given date using COBOL intrinsic functions.
18. A MedClaim claim has a service date of 20240101 and a received date of 20240615. The payer's timely filing limit is 180 days. Is the claim timely? Show the calculation.
19. Explain the difference between date windowing and date expansion as Y2K remediation strategies. What is the long-term risk of windowing?
20. How would you compute the last day of the current month in COBOL? (Consider months with 28, 29, 30, and 31 days.)
Answer Key
- c — CURRENT-DATE returns 21 characters: 8 date + 8 time + 5 GMT offset.
- b — Convert both dates to integers using INTEGER-OF-DATE and subtract.
- c — 1900 is divisible by 100 but not by 400, so it is NOT a leap year.
- b — Date expansion converts 2-digit years to 4-digit years permanently.
- c — Positions 17-21 contain the GMT offset: sign (+ or -), hours (2 digits), minutes (2 digits).
- b — INTEGER-OF-DATE returns the number of days since the COBOL epoch (January 1, 1601).
- b — DATE-OF-INTEGER converts an integer day number back to YYYYMMDD format.
- c — The complete leap year rule: divisible by 4, EXCEPT divisible by 100, EXCEPT divisible by 400.
- c — An invalid date (e.g., 20240231) causes a runtime abend.
- b — With pivot year 50, years 00-49 are interpreted as 2000-2049.
- False — Direct subtraction gives 20240301 - 20240228 = 73, but the actual difference is 2 days (or 1 day in non-leap years). Use INTEGER-OF-DATE for correct arithmetic.
- True — Positions 17-21 provide the GMT offset.
- False — 1900 is not a leap year (divisible by 100 but not 400), so February 29, 1900 is invalid.
- True — COBOL 2002 standardized 4-digit year usage in date-related features.
- False — IBM's Language Environment uses October 15, 1582 (start of the Gregorian calendar) as day 1, while COBOL's INTEGER-OF-DATE uses January 1, 1601.
- 20240301 - 20240228 = 73 (numeric subtraction of two 8-digit numbers). But the actual difference is 2 days (Feb has 29 days in 2024, a leap year). The correct approach:
FUNCTION INTEGER-OF-DATE(20240301) - FUNCTION INTEGER-OF-DATE(20240228)= 2. Numeric subtraction treats dates as plain numbers, ignoring calendar structure. - Compute
FUNCTION INTEGER-OF-DATE(date), thenFUNCTION MOD(result - 1, 7) + 1. This gives a value 1-7 mapping to days of the week. Calibrate by testing with a known date (e.g., 2024-01-01 = Monday). Adjust the formula if the mapping differs from expected. - Days elapsed = INTEGER-OF-DATE(20240615) - INTEGER-OF-DATE(20240101) = 166 days. 166 <= 180, so the claim IS timely (filed 14 days before the deadline).
- Windowing preserves 2-digit years and uses a pivot year to interpret century: years above the pivot are 19xx, below are 20xx. It was faster to implement but creates a new expiration date (e.g., pivot year 50 expires in 2050). Expansion converts all date fields to 4-digit years permanently, requiring changes to files, databases, copybooks, and programs. It is more work but has no expiration. The long-term risk of windowing is that the pivot year will eventually be reached, requiring another remediation effort.
- Compute the first day of the NEXT month, then subtract 1 day: (1) If current month < 12, set next-month-date to YYYYMM+1 01. If month = 12, set to YYYY+1 0101. (2) Compute INTEGER-OF-DATE(next-month-date) - 1. (3) Convert back using DATE-OF-INTEGER. The resulting date is the last day of the current month, correctly handling all month lengths and leap years.