Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Date Difference in months

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
sriram_motamarri
Warnings : 1

New User


Joined: 14 Sep 2006
Posts: 11
Location: Chennai

PostPosted: Sat Jan 09, 2010 5:53 pm    Post subject: Date Difference in months
Reply with quote

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
View user's profile Send private message

dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6968
Location: porcelain throne

PostPosted: Sat Jan 09, 2010 6:46 pm    Post subject:
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6968
Location: porcelain throne

PostPosted: Sun Jan 10, 2010 7:00 am    Post subject:
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6968
Location: porcelain throne

PostPosted: Sun Jan 10, 2010 7:08 am    Post subject:
Reply with quote

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
View user's profile Send private message
sriram_motamarri
Warnings : 1

New User


Joined: 14 Sep 2006
Posts: 11
Location: Chennai

PostPosted: Sun Jan 10, 2010 11:49 am    Post subject:
Reply with quote

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
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Mon Jan 11, 2010 2:57 am    Post subject:
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10274
Location: italy

PostPosted: Tue Jan 12, 2010 11:27 pm    Post subject: Reply to: Date Difference in months
Reply with quote

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
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Wed Jan 13, 2010 12:17 am    Post subject: Reply to: Date Difference in months
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts How to add header with Date(YYMMDD) i... Rajan Moorthy DFSORT/ICETOOL 2 Thu Jul 06, 2017 11:44 pm
No new posts Validate date and numeric fields and ... Rick Silvers DFSORT/ICETOOL 6 Thu May 11, 2017 6:51 pm
No new posts LISTIDR compiled date/time jerryte IBM Tools 3 Thu Apr 20, 2017 7:37 pm
No new posts SUBSTR for Date functions Shaheen Shaik DB2 4 Thu Apr 06, 2017 2:14 pm
No new posts Date and time format in CICS Chandru3183 CICS 2 Sat Mar 18, 2017 12:46 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us