COBOL with Dates Handling



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

COBOL with Dates Handling

Postby ramrajgk » Sat Sep 05, 2015 11:15 pm

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
ramrajgk
 
Posts: 6
Joined: Sat Sep 05, 2015 9:18 pm
Has thanked: 0 time
Been thanked: 0 time

Re: COBOL with Dates Handling

 

Re: COBOL with Dates Handling

Postby NicC » Sun Sep 06, 2015 12:08 am

Do you mean subtracted?

Convert to lilian format, subtract 6 and convert back again.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 2690
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisys (almost)
Has thanked: 4 times
Been thanked: 105 times

Re: COBOL with Dates Handling

Postby ramrajgk » Sun Sep 06, 2015 12:39 am

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
ramrajgk
 
Posts: 6
Joined: Sat Sep 05, 2015 9:18 pm
Has thanked: 0 time
Been thanked: 0 time

Re: COBOL with Dates Handling

Postby Robert Sample » Sun Sep 06, 2015 1:37 am

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.
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: East Dubuque, Illinois
Has thanked: 1 time
Been thanked: 222 times

Re: COBOL with Dates Handling

Postby ramrajgk » Sun Sep 06, 2015 1:55 am

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.
ramrajgk
 
Posts: 6
Joined: Sat Sep 05, 2015 9:18 pm
Has thanked: 0 time
Been thanked: 0 time

Re: COBOL with Dates Handling

Postby BillyBoyo » Sun Sep 06, 2015 2:13 am

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.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: COBOL with Dates Handling

Postby enrico-sorichetti » Sun Sep 06, 2015 3:16 am

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:
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2643
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 130 times

Re: COBOL with Dates Handling

Postby ramrajgk » Sun Sep 06, 2015 3:25 am

I am sorry Enrico and Billy.

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

Regards,
Ram
ramrajgk
 
Posts: 6
Joined: Sat Sep 05, 2015 9:18 pm
Has thanked: 0 time
Been thanked: 0 time

Re: COBOL with Dates Handling

Postby Robert Sample » Sun Sep 06, 2015 3:40 am

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.
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: East Dubuque, Illinois
Has thanked: 1 time
Been thanked: 222 times

Re: COBOL with Dates Handling

Postby NicC » Sun Sep 06, 2015 2:18 pm

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.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 2690
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisys (almost)
Has thanked: 4 times
Been thanked: 105 times

Next

Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post