Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with FUNCTION 3

Status
Not open for further replies.

Faustino29

Programmer
Mar 24, 2001
5
BE
I would like use the instruction FUNCTION with the dates...But I don't know which instruction of these two is right (or are the two right??)

1. FUNCTION DATE-TO-INTEGER (zone)
with zone : YYYYMMDD
which returns the number of days since 1/1/1600

OR

2. FUNCTION INTEGER-OF-DATE (num)
with num : YYYYMMDD
which also returns the number of days since 1/1/1600

Thank you!!!
Faustino.

 
Hello Faustino

Are you italian?
Here is a little solution to count number of days giving two dates..See the sample code below
...
...
WORKING-STORAGE SECTION.
01 START-DATE PIC 9(8).
01 FILLER REDEFINES START-DATE.
02 START-YEAR PIC 9(4).
02 START-MONTH PIC 99.
02 START-DAY PIC 99.
01 END-DATE PIC 9(8).
01 FILLER REDEFINES END-DATE.
02 END-YEAR PIC 9(4).
02 END-MONTH PIC 99.
02 END-DAY PIC 99.
01 DIFF-DAYS PIC 9(6).

..
..
PROCEDURE DIVISION.
CALC-DAYS.
MOVE 1600 TO START-YEAR
MOVE 01 TO START-MONTH
START-DAY
MOVE 2001 TO END-YEAR
MOVE 05 TO END-MONTH
MOVE 26 TO END-DAY
COMPUTE DIFF-DAYS =
(FUNCTION INTEGER-OF-DATE(START-DATE)) -
(FUNCTION INTEGER-OF-DATE(END-DATE))
...
...
Using this approach you can obtain the numbers of days between two dates..

That's All!!

Hope in this help


 

So, my second instruction was good...

Thank you very much...

Faustino

 
These two functions are reciprocals of each other. INTEGER-OF-DATE converts from a Gregorian date in integer form to an integer representing the number of days since December 31, 1600 in the Gregorian calendar.

DATE-OF-INTEGER converts from number of days since December 31, 1600 in integer form to a Gregorian Date stored in integer form (YYYYMMDD).

Both of your functions are valid (except the use of -TO- instead of -OF-). Use the one that fits what you want to do.

Glenn - Brainbench MVP for COBOL II
 
In addition to the reciprocal connection, I guess we should mention the Gregorian/Julian connection for completness:

DATE relates to Gregorian dates
DAY relates to Julian dates

e.g.: DATE-OF-INTEGER will produce a YYYYMMDD date
DAY-OF-INTEGER will produce a YYYYDDD date
 
My memory is that RM COBOL supports the High Level of the '85 COBOL Standard but does NOT include support for intrinsic functions introduced in the 1989 Amemendment. (Similar to IBM - where VS COBOL II supports the '85 Standard, but their LE-conforming compilers also support intrinsic functions.)

Bill Klein
 
Okay. So what would be a solution to finding the difference of days between 2 different dates?

I have a test that the date field must pass; it must be less than 10 days ago from today's date.
 
The link to the date.zip file did the trick. That was rather straight forward, easy to understand code that was provided.

Thanks.
-David
 
This is a very good link which many COBOL programmers out there will value.

Sorry, can't give you more than one star.

Dimandja
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top