View previous topic :: View next topic
|
Author |
Message |
shanudarling Warnings : 1 New User
Joined: 20 Dec 2006 Posts: 55 Location: noida
|
|
|
|
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.
Please help. |
|
Back to top |
|
|
Ketan Varhade
Active User
Joined: 29 Jun 2009 Posts: 197 Location: Mumbai
|
|
|
|
Hi,
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 |
|
Back to top |
|
|
Srihari Gonugunta
Active User
Joined: 14 Sep 2007 Posts: 295 Location: Singapore
|
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
Quote: |
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 )
Quote: |
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" |
|
Back to top |
|
|
arvind.m
Active User
Joined: 28 Aug 2008 Posts: 205 Location: Hyderabad
|
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
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. |
Why would 1 OCT be "1 month before" 31 OCT? I've seen many implementations of date "arithmetic" and "1 month before" never yielded a date in the same month. . .
As Enrico mentioned, the "rules" must be well understood before someone starts slinging code. And these rules should not be created by individual programmers/analysts/dba's, etc. |
|
Back to top |
|
|
|