View previous topic :: View next topic
|
Author |
Message |
sriram_motamarri Warnings : 1 New User
Joined: 14 Sep 2006 Posts: 11 Location: Chennai
|
|
|
|
Hi
Can anyone help me on this.
I have two dates in the format
CYYMMDD
I need logic to calculate no of months between them....
let me know if any function is available...
Thanks,
Sriram |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
you can always use combinations of Language Environment (LE) routines to accomplish what you want. there may even be a direct month calculation routine, but you will have to look at one of the LE Manuals |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
had another thought.
most shops (all shops that I have been at),
have their own 'date routines'.
this allows for business considerations and most importantly consistency.
suggest that you take a look at your site's application documentation and
speak to someone with some experience and knowledge of your site,
especially if you are some kind of outsourcing unit. Find out what exists. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
and another thought.
calculation of month intervals does not have to take into consideration leap years, short or long months. partial month consideration is the only concern.
if indeed this is the first date routine being created for your shop,
you need to establish rules.
do you have to consider partial months?
Jan 1 to Feb 1 is obvious.
what should be the calculated months for:
Jan 10 to Feb 1??
Jan 1 to Feb 20?? |
|
Back to top |
|
|
sriram_motamarri Warnings : 1 New User
Joined: 14 Sep 2006 Posts: 11 Location: Chennai
|
|
|
|
Hi Dick,
Thanks for the information.....
For my requirement no need to consider partial months...
For Jan 10 to Feb 1??
The result should be zero...
For Jan 1 to Feb 20??
The result should be one... |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
For my requirement no need to consider partial months... |
Doubtful. . . One way or another this will be considered.
As DBZ mentioned, organizations typically have routines that are to be used. Even if there are no invokable routines, there are date/calendar rules to be followed. You need to learn the rules of your organization (do not make up your own) and implement your code using these. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
Quote: |
For Jan 10 to Feb 1??
The result should be zero...
For Jan 1 to Feb 20??
The result should be one... |
so You need to make the computation in days , convert to months and truncate the remainder
I strongly suggest You speak to the powers of Your organization,
what are You going to use for the month length??
a difference of distant dates might give unexpected results
strong confirmation, not a technical issue yet, but a standards one
( year length, month length, ...)
come back once thes eissues have been clarified |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
If your compiler supports COBOL INTRINSIC FUNCTIONS, an alternative would be to use INTEGER-OF-DATE (format=CCYYMMDD) or INTEGER-OF-DAY (format=CCYYDDD), to calculate the number of days between the two dates.
However, I agree 100% with Dick's suggestion of using Language Environment routines, regardless. In your case, calling CEEDAYS twice to obtain the lilian days associated with each date and then subtract one from the other to arrive at the number of days difference.
So, Language Environment routines are recommended because COBOL INTRINSIC FUNCTIONS will crash and burn if an invalid date is passed to the FUNCTION, whereas, LE relies upon the first two-bytes (binary-halfword) of the 12-byte Feedback-Area parm to inform the Caller whether a given date is valid or invalid.
Bill |
|
Back to top |
|
|
|