IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Date Difference in months


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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: 6966
Location: porcelain throne

PostPosted: Sat Jan 09, 2010 6:46 pm
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: 6966
Location: porcelain throne

PostPosted: Sun Jan 10, 2010 7:00 am
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: 6966
Location: porcelain throne

PostPosted: Sun Jan 10, 2010 7:08 am
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
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

Moderator Emeritus


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

PostPosted: Mon Jan 11, 2010 2:57 am
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Tue Jan 12, 2010 11:27 pm
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Wed Jan 13, 2010 12:17 am
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replacing 'YYMMDD' with date, varying... SYNCSORT 3
No new posts Modifying Date Format Using DFSORT DFSORT/ICETOOL 9
No new posts Need to convert date format DFSORT/ICETOOL 20
No new posts Need help to append a date&tsp at... DFSORT/ICETOOL 9
No new posts Fetch data from programs execute (dat... DB2 3
Search our Forums:

Back to Top