Difference in days between two dates(mmddyy).



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

Difference in days between two dates(mmddyy).

Postby raj mystery » Thu Dec 23, 2010 11:46 pm

I have two dates in a file and want to find the difference between these two dates in number of days through Cobol program.
These dates are in MMDDYY format.
example:-
date1-110410
date2-112210

Please reply it's urgent for me.

Thanks.
raj mystery
 
Posts: 2
Joined: Thu Dec 23, 2010 11:40 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Difference in days between two dates(mmddyy).

Postby NicC » Thu Dec 23, 2010 11:56 pm

a) we do not do urgent - we do as and when we can
b) what have you tried so far?
c) it is as easy as a walk in the park if you did it in Rexx (which can be called from COBOL)
d) have you looked up ny of the LE (Language Environment) routines to see if they do what you want?
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

Re: Difference in days between two dates(mmddyy).

Postby raj mystery » Fri Dec 24, 2010 9:39 am

Thanks for your reply.
I am very beginner in this area and in learning phase.

I have saw some date function but in this format these are not applicable like integer-of-date function but it takes input date in yyyymmdd format so not able to find.
raj mystery
 
Posts: 2
Joined: Thu Dec 23, 2010 11:40 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Difference in days between two dates(mmddyy).

Postby dick scherrer » Fri Dec 24, 2010 10:24 am

Hello,

You will probably have to reformat the input dates you have so they will be usable by date routines.

You will have to consider how to determine the century - your organization probably has a rule for this.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: Difference in days between two dates(mmddyy).

Postby gugul » Thu Jan 13, 2011 8:37 pm

You can use DB2

set :ws-days = DAYS(DATE('2011-12-31')) - DAYS(DATE('2011-01-13'))
gugul
 
Posts: 6
Joined: Thu Jan 13, 2011 8:13 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Difference in days between two dates(mmddyy).

Postby Robert Sample » Thu Jan 13, 2011 9:26 pm

gugul, where -- exactly -- in the original post was DB2 mentioned? Since DB2 is a costly product, not all sites have it (mine does not, for example). Therefore, your solution will not work at all sites, is incorrectly posted in a COBOL forum, and does not address the original problem at all.
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Difference in days between two dates(mmddyy).

Postby gugul » Thu Jan 13, 2011 9:32 pm

Robert Sample wrote:gugul, where -- exactly -- in the original post was DB2 mentioned? Since DB2 is a costly product, not all sites have it (mine does not, for example). Therefore, your solution will not work at all sites, is incorrectly posted in a COBOL forum, and does not address the original problem at all.


Didn't thought of that
thanks
gugul
 
Posts: 6
Joined: Thu Jan 13, 2011 8:13 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Difference in days between two dates(mmddyy).

Postby Akatsukami » Thu Jan 13, 2011 9:38 pm

raj mystery wrote:I have two dates in a file and want to find the difference between these two dates in number of days through Cobol program.
These dates are in MMDDYY format.
example:-
date1-110410
date2-112210

Please reply it's urgent for me.

Thanks.

Aside from the century windowing, your problem is completely handled by the Language Environment functions CEEDAYS and CEEDATE. Setting the century window can be done if necessary with CEESCEN, although you will have to ask your site support personnel or sempai what value to use.
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day
User avatar
Akatsukami
Global moderator
 
Posts: 1058
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times

Re: Difference in days between two dates(mmddyy).

Postby mickeywhite » Fri Jan 14, 2011 10:56 pm

Here is a cobol pgm that interacts with tso thru REXX. I will post the COBOL pgm first, then rex code to execute it interactively. (it does some minor edits)

       identification division.

       program-id.             daysdiff.
      *************************************************
      **** returns number of days between two dates.
      *************************************************

       environment division.

       data division.

       working-storage section.
       77 w-d1                                              pic x(08).
       77 w-d2                                              pic x(08).
       77 n-d1                                              pic 9(08).
       77 n-d2                                              pic 9(08).
       77 w-i1                                              pic 9(09).
       77 w-i2                                              pic 9(09).
       77 w-days                                            pic 9(09).

       procedure division.
           display ' '
           display ' '
           display ' '
           display ' '
           display ' '

           display 'enter valid first date yyyymmdd and press enter'
           accept w-d1 from sysin
           if  w-d1 not numeric
               display ' first date not numeric '
               move 1 to return-code
               goback
           end-if
           move w-d1 to n-d1
           if  (n-d1 > 99991231)
               display ' date must be less than 99991232'
               move 3 to return-code
               goback
           end-if
           if  (n-d1 < 16010101)
               display ' date must be greater than 16010100'
               move 3 to return-code
               goback
           end-if

           display 'enter valid second date yyyymmdd and press enter'
           accept w-d2 from sysin
           if  w-d2 not numeric
               display 'second date not numeric '
               move 2 to return-code
               goback
           end-if
           move w-d2 to n-d2
           if  (n-d2 > 99991231)
               display ' date must be less than 99991232'
               move 4 to return-code
               goback
           end-if
           if  (n-d2 < 16010101)
               display ' date must be greater than 16010100'
               move 4 to return-code
               goback
           end-if

           compute w-i1 = function integer-of-date(n-d1)
           compute w-i2 = function integer-of-date(n-d2)
           compute w-days = w-i1 - w-i2

           display 'the number of days between ' w-d1 ' and '
                    w-d2 ' is ' w-days

           move 0 to return-code
           goback
           .



Here is the Rexx code, (you have to put your load library name in the place of LOAD.LIB.NAME)

/* REXX */
 "ALLOCATE F(SYSOUT) DA(*) SHR REUSE"
 "ALLOCATE F(SYSIN) DA(*) SHR REUSE"
 "CALL 'LOAD.LIB.NAME(DAYSDIFF)' "
 "FREE FILE(SYSOUT SYSIN)"
   EXIT
mickeywhite
 
Posts: 11
Joined: Tue Nov 02, 2010 8:04 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Difference in days between two dates(mmddyy).

Postby ankesh.cs2007 » Sun Jan 16, 2011 11:39 pm

Good mickeywhite.
ankesh.cs2007
 
Posts: 4
Joined: Wed Jan 12, 2011 1:46 am
Location: meerut, india
Has thanked: 0 time
Been thanked: 0 time


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post