Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

end of month calculation

Status
Not open for further replies.

hugheskbh

Programmer
Dec 18, 2002
37
0
0
US
Can someone help me calculate the end of month date in a calendar month in cobol?
 
Hi Hugh,

If you know how to define a table in cobol and you know the rule "Thirty days hath Sept..." and you know month 1 is JAN, month 2 is Feb, etc., you should be able to solve your problem. Was this a big enough hint?

Regards, Jack.
 
Hi Hugh,
If you fancy learning a few of the slightly more unusual functions that Cobol has, you could use the DATE-OF-INTEGER and INTEGER-OF-DATE functions to achieve this. Let's suppose that you want to know the last date of the last day in February next year. You could:
a)Set a field with the value 01-03-2003
b)Use the INTEGER-OF-DATE function to give you a number, and then subtract 1 from that number.
c)Use the DATE-OF-INTEGER function to get you back the last day in February.

OK, I'll admit that this is a little on the esoteric side, but it will work, and will give you an insight into some of the less used features in Cobol.

Marc
 
Marc,

You forgot to mention that you were using the europeen date format dd-mm-yyyy - as opposed to the american date format mm-dd-yyyy.

Dimandja
 
Marc,

Your post reminded me that I forgot to mention to Hugh that he has to test the year for leap year and add 1 to the Feb days in the table.

Hugh,

It's a little more than dividing by 4. Let us know how far you've gotten. We'll be happy to help you from there if you get stuck.


Regards, Jack.
 
I put out some sample code in a FAQ which implements the method suggested by Marc. It could easily be adapted for your purpose. Clive
 
The FUNCTION method for finding the # of days in a month (i.e., the last day of the month) is ok for 1 or 2 or a handful of dates. If you plan to use it for each date in a record of an IP file, the performance hit may argue against it.

Regards, Jack.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top