HP3000-L Archives

January 2000, Week 3

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Erik Vistica <[log in to unmask]>
Reply To:
Erik Vistica <[log in to unmask]>
Date:
Wed, 19 Jan 2000 16:20:34 -0800
Content-Type:
text/plain
Parts/Attachments:
text/plain (97 lines)
From our database...


W1683622
How to do date calculations in COBOL

Problem Description

How can I do date calculations in COBOL?  Working with calendar dates
(year, month, day), I want to be able to determine the number of days
between two dates, and I want to be able to find the date that is a
specified number of days before or after a given date.

Configuration Info

HP 3000
MPE/iX (3.0 retrofit, 3.1, and later releases)
COBOL II/XL version A.04.03 and later

Solution

This Note illustrates the use of COBOL intrinsic functions to perform
date conversion and calculations.  These functions are provided by the
Intrinsic Function module of COBOL, which is supported beginning with
COBOL II/XL version A.04.03.  COBOL intrinsic functions (not to be
confused with MPE intrinsics) are part of the COBOL language, and a
program using them should be portable to any COBOL compiler that
implements the Intrinsic Function module (ANSI X3.23a-1989).

COBOL intrinsic functions are NOT available in COBOL II/V, so this
technique applies only in programs compiled to Native Mode on MPE/iX.

The following program demonstrates the use of two functions,
INTEGER-OF-DATE and DATE-OF-INTEGER.  Function INTEGER-OF-DATE converts
a date in YYYYMMDD format to an integer date equivalent, starting with
January 1, 1601, of the Gregorian calendar.  Function DATE-OF-INTEGER
does the opposite, converting an integer date to its standard date
equivalent.

For more information on these COBOL intrinsic functions, see the
HP COBOL II/XL Reference Manual (part number 31500-90001).

000010$CONTROL POST85
000020 IDENTIFICATION DIVISION.
000030 PROGRAM-ID.  MURRAY.
000040*
000050*    DEMONSTRATE THE USE OF COBOL INTRINSIC FUNCTIONS
000060*    FOR DATE CONVERSION.  NOTE THE USE OF THE POST85
000070*    OPTION, WHICH IS REQUIRED.
000080*
000090 DATA DIVISION.
000100 WORKING-STORAGE SECTION.
000110 77  DELTA          PIC ++++9.
000120 77  FUTURE-DATE    PIC 9999B99B99.
000130 PROCEDURE DIVISION.
000140 0.
000150*
000160*    WHAT IS THE DIFFERENCE IN DAYS BETWEEN
000170*    FEBRUARY 28, 1992, AND MARCH 2, 1992?
000180*    (ANSWER: 3)
000190     COMPUTE DELTA =
000200             FUNCTION INTEGER-OF-DATE (19920302) -
000210             FUNCTION INTEGER-OF-DATE (19920228).
000220     DISPLAY "DELTA = ", DELTA.
000230*
000240*    WHAT WILL BE THE DATE 365 DAYS IN THE FUTURE
000250*    FROM AUGUST 15, 1999?
000260*    (ANSWER: AUGUST 14, 2000)
000270     COMPUTE FUTURE-DATE =
000280             FUNCTION DATE-OF-INTEGER
000290                 (365 + FUNCTION INTEGER-OF-DATE (19990815)).
000300     DISPLAY "FUTURE-DATE = ", FUTURE-DATE.
000310*
000320     STOP RUN.

COB85XLG test
...

DELTA =    +3
FUTURE-DATE = 2000 08 14



Joe Smith wrote:
>
> I just got a question on date calculations from one of our Cobol programmers,
> but its been a long time since I used the calendar / date intrinsics.
> Basically, the programmer wants to display the current date in the format
> mm/dd/yy and then do a calculation of the current date + nn days, then display
> the revised date in the same format.
>
> This is a work scheduling application that has been in production for some time,
> and it failed in the Y2K (they just found out).  The process they used before
> was rather unbelievable, they calculated the julian date and did all
> manipulations without using any intrinsics.  It is quite hard to follow.  They
> want to get it right this time, so any help would be appreciated.

ATOM RSS1 RSS2