Page 1 of 2

COBOL with Dates Handling

PostPosted: Sat Sep 05, 2015 11:15 pm
by ramrajgk
Hi,

Can you please help me on the below requirement.

With the current date(05/09/2015) i need the date with the 6 negated (31/08/2015).

Currently, i am thinking move this current date into Julian date and negate into 6 then getting back the same date into CCYY/MM/DD format.

Will it helpful to achieve the above requirement?

Thanks in advance,
Ram

Re: COBOL with Dates Handling

PostPosted: Sun Sep 06, 2015 12:08 am
by NicC
Do you mean subtracted?

Convert to lilian format, subtract 6 and convert back again.

Re: COBOL with Dates Handling

PostPosted: Sun Sep 06, 2015 12:39 am
by ramrajgk
thanks for your quick response Nicc.

Yes i mean subtract the dates. can you please let me know what is lillian format? Can you please guide me if there is any material or any useful thread in this forum i can use it as reference to work with my requirement . I am sorry to say this here, I am not aware the concepts of Julian/Gregorian/Lilian dates conversion from the current system dates.

Thanks again,
Ram

Re: COBOL with Dates Handling

PostPosted: Sun Sep 06, 2015 1:37 am
by Robert Sample
Assuming you are NOT using a very old release of COBOL, you can use intrinsic functions. INTEGER-OF-DATE converts a YYYYMMDD date to an integer value; you can then subtract 6 from that value and then use DATE-OF-INTEGER to convert back to a YYYYMMDD variable.

Re: COBOL with Dates Handling

PostPosted: Sun Sep 06, 2015 1:55 am
by ramrajgk
Hi Robert,

DATE-OF-INTEGER will work fine, if we are processing it in the same month after 7th day of the month, but my case is different when i subtract 05/09/2015 (05-September-2015), it should get the 31/08/2015(31-August-2015), i believe if i work with DATE-OF-INTEGER concept it will not the 31st August right? Correct me if i am wrong and can you please let me know if there is any other possibilities.

Re: COBOL with Dates Handling

PostPosted: Sun Sep 06, 2015 2:13 am
by BillyBoyo
Why do you feel it would not work? Did you try it? Your site probably has date-routines you can CALL. Ask around where you work.

As well as the intrinsic functions mentioned, there are some Language Environment callable routines which will work as well.

Do it whichever way your colleagues do it already, rather than introducing a new wheel of possible faulty design.

Re: COBOL with Dates Handling

PostPosted: Sun Sep 06, 2015 3:16 am
by enrico-sorichetti
i believe if i work with DATE-OF-INTEGER concept it will not the 31st August right? Correct me if i am wrong and can you please let me know if there is any other possibilities.

why speculate and post irrelevant comments instead of reading the manual or testing ???

Your_int_date         = INTEGER_OF_DATE(Your_date)
Your_int_date_minus_6 = Your_int_date  - 6
Your_date_minus_6 = DATE_OF_INTEGER(Your_int_date_minus_6)


does not seem too difficult to test :evil:

Re: COBOL with Dates Handling

PostPosted: Sun Sep 06, 2015 3:25 am
by ramrajgk
I am sorry Enrico and Billy.

I will test and get back to you, if i still face any problem on this.

Regards,
Ram

Re: COBOL with Dates Handling

PostPosted: Sun Sep 06, 2015 3:40 am
by Robert Sample
It is obvious that you did not bother to even read the manual before posting. From the Enterprise COBOL Language Reference manual on the INTEGER-OF-DATE function:
The returned value is an integer that is the number of days that the date represented by argument-1 succeeds December 31, 1600 in the Gregorian calendar.
And from the same manual on the DATE-OF-INTEGER function:
argument-1 A positive integer that represents a number of days succeeding December 31, 1600, in the Gregorian calendar. The valid range is 1 to 3,067,671, which corresponds to dates ranging from January 1, 1601 thru December 31, 9999.
So the first function will convert your date to a number of days since December 31, 1600. You can add or subtract a number of days (as long as you don't exceed the limits of 0 to 3,067,671) and you still have a number of days since December 31, 1600. Since the DATE-OF-INTEGER function converts the number of days since December 31, 1600 to a date value, WHY would you think there would be any problem with months (or even years) since you're dealing with an integer value, NOT date values?

The next time you post a problem and then start complaining that the response doesn't solve your problem, you would be wise to at least READ THE MANUAL before you post your erroneous guesses. Better yet, TEST THE SOLUTION and if it doesn't provide you what you want, then you can at least provide your test data, the actual result, and what you expected the result to be.

Re: COBOL with Dates Handling

PostPosted: Sun Sep 06, 2015 2:18 pm
by NicC
I know that my response works because I used it myself. I had to look up the manual, not ask on a forum. That is why I know it is called Lilian - or maybe Lillian. You really should do your own research first and only come to a forum when you are having problems with what you have found and tried.