Performing calculations on date and time values

Language Environment stores a date as a fullword binary integer and a timestamp as a doubleword floating-point value. You can use these formats to perform arithmetic calculations on date and time values, instead of writing special subroutines to do so. Figure 1 is an example of how you can use Language Environment date and time services to convert a date to a different format and perform a simple calculation on the formatted date.

In this example, the number of years of service for an employee is determined using the original date of hire in the format YYMMDD to make the calculations. The example calculates the total number of years of service for an employee by first calling CEEDAYS to convert the days to Lilian and by then calling CEELOCT (Get Current Local Time) to get the current local time. Then, doh_Lilian is subtracted from today_Lilian (the number of days from the beginning of the Gregorian calendar to the current local time) to calculate the employee's total number of days of employment. The final calculation divides that number by 365.25 to get the number of service years.

Figure 1. Performing calculations on dates
CALL CEEDAYS (date_of_hire, 'YYMMDD', doh_lilian, fc)
CALL CEELOCT (today_Lilian, today_seconds, today_Gregorian, fc)
service_days = today_Lilian - doh_Lilian
service_years = service_days / 365.25

The valid Lilian date range is 15 October 1582 to 31 December 9999. However, COBOL intrinsic functions uses the COBOL Integer date 01 January 1601 as day one. Language Environment provides the CEECBLDY callable service to allow you to work with the COBOL Integer date format. See z/OS Language Environment Programming Reference for more information about the CEECBLDY service.