Monday, September 26, 2011

COBOL : Difference beteen dates

Do you know any easy ways (COBOL) to find:

1. The difference between two Gregorian dates
2. The difference between two Julian dates 


Well, it is quite simple if you use COBOL instrinsic functions. Here's how you can do it:

The difference between two Gregorian dates

Working-Storage Section.
01 WS-DIFFERENCE PIC 9(08).
01 WS-DATE-1     PIC 9(08) VALUE 19981223.
01 WS-DATE-2     PIC 9(08) VALUE 19990104.
Procedure Division.
COMPUTE WS-DIFFERENCE = FUNCTION INTEGER-OF-DATE (WS-DATE-2)
                      - FUNCTION INTEGER-OF-DATE (WS-DATE-1)

The difference between two Julian dates

Working-Storage Section.
01 WS-DIFFERENCE PIC 9(08).
01 WS-DATE-1 PIC 9(07) VALUE 1998357.
01 WS-DATE-2 PIC 9(07) VALUE 1999004.
Procedure Division.
COMPUTE WS-DIFFERENCE = FUNCTION INTEGER-OF-DAY (WS-DATE-2)
                      - FUNCTION INTEGER-OF-DAY (WS-DATE-1).

 So easy, right?

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.