Page 1 of 1

Difference in days between two dates(mmddyy).

PostPosted: Thu Dec 23, 2010 11:46 pm
by raj mystery
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.

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

PostPosted: Thu Dec 23, 2010 11:56 pm
by NicC
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?

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

PostPosted: Fri Dec 24, 2010 9:39 am
by raj mystery
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.

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

PostPosted: Fri Dec 24, 2010 10:24 am
by dick scherrer
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.

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

PostPosted: Thu Jan 13, 2011 8:37 pm
by gugul
You can use DB2

set :ws-days = DAYS(DATE('2011-12-31')) - DAYS(DATE('2011-01-13'))

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

PostPosted: Thu Jan 13, 2011 9:26 pm
by Robert Sample
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.

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

PostPosted: Thu Jan 13, 2011 9:32 pm
by gugul
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

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

PostPosted: Thu Jan 13, 2011 9:38 pm
by Akatsukami
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.

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

PostPosted: Fri Jan 14, 2011 10:56 pm
by mickeywhite
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

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

PostPosted: Sun Jan 16, 2011 11:39 pm
by ankesh.cs2007
Good mickeywhite.