I have a query regarding the manipulation of date.
I have a future date (in CCYYMMDD format) and I have to find out 1 month before date.
For example -
Future date = 12 Oct 2009, 1 month before = 12 Sep 2009
Future date = 31 Oct 2009, 1 month before = 31 Sep 2009 which is wrong. In this case I want the date as 1 Oct 2009.
Is there any COBOL function which can handle this?
The processing I am looking for is not in terms of no. of days. I want a valid date after subtracting 1 from the month field of the future date.
There are many shops which have internal utilities which do such operation,
I have heard that in COBOL II that have some function which perform date operation but if this is not possible then you have to use the DB2 for doing the above mentioned requirement
Future date = 31 Oct 2009, 1 month before = 31 Sep 2009 which is wrong.
In this case I want the date as 1 Oct 2009.
two issues to point out...
- if the program is not dealing with DB2 it is silly to introduce a DB2 dependency simply for date calculations
- Your requirement is not satisfied by the common available practices for date calculations ( db2 at least )
Incrementing and decrementing dates: The result of adding a duration to a date, or of subtracting a duration from a date, is itself a date. (For the purposes of this operation, a month denotes the equivalent of a calendar page. Adding months to a date, then, is like turning the pages of a calendar, starting with the page on which the date appears.) The result must fall between the dates January 1, 0001 and December 31, 9999 inclusive. If a duration of years is added or subtracted, only the year portion of the date is affected. The month is unchanged, as is the day unless the result would be February 29 of a non-leap-year. Here the day portion of the result is set to 28, and the SQLWARN6 field of the SQLCA is set to W, indicating that an end-of-month adjustment was made to correct an invalid date. DB2 Application Programming and SQL Guide also describes how SQLWARN6 is set.
Similarly, if a duration of months is added or subtracted, only months and, if necessary, years are affected. The day portion of the date is unchanged unless the result would be invalid (September 31, for example). In this case the day is set to the last day of the month, and the SQLWARN6 field of the SQLCA is set to W to indicate the adjustment.
so You will have to write Your own code anyway
but i find odd that many, too many, organizations have not yet
defined and implemented a common set of rules and subroutines for date calculations
the whole issue is quite murky, legal and standards concerns included
( for example which is the first and last week of the year,
how many weeks in a year, sometimes 52, sometimes 53 )
not an issue to be dealt by each application programmer (*)
(*) hope that it is the politically correct job description..
car salesmen prefer to be called "mobility consultants"