Rational Developer for System z
COBOL for Windows, Version 7.5, Programming Guide


Example: manipulating dates

The following example shows how to use date and time callable services to convert a date to a different format and do a simple calculation with the formatted date.

CALL CEEDAYS USING dateof_hire, 'YYMMDD', doh_lilian, fc.
CALL CEELOCT USING todayLilian, today_seconds, today_Gregorian, fc.
COMPUTE servicedays  = today_Lilian - doh_Lilian.
COMPUTE serviceyears = service_days / 365.25.

The example above uses the original date of hire in the format YYMMDD to calculate the number of years of service for an employee. The calculation is as follows:

  1. Call CEEDAYS (Convert Date to Lilian Format) to convert the date to Lilian format.
  2. Call CEELOCT (Get Current Local Time) to get the current local time.
  3. Subtract doh_Lilian from today_Lilian (the number of days from the beginning of the Gregorian calendar to the current local time) to calculate the employee's number of days of employment.
  4. Divide the number of days by 365.25 to get the number of service years.

Terms of use | Feedback

Copyright IBM Corporation 1996, 2008.
This information center is powered by Eclipse technology. (http://www.eclipse.org)