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

Date manipulation


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
shanudarling
Warnings : 1

New User


Joined: 20 Dec 2006
Posts: 55
Location: noida

PostPosted: Thu Sep 10, 2009 3:35 pm
Reply with quote

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

Active User


Joined: 29 Jun 2009
Posts: 197
Location: Mumbai

PostPosted: Thu Sep 10, 2009 3:59 pm
Reply with quote

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

Active User


Joined: 14 Sep 2007
Posts: 295
Location: Singapore

PostPosted: Thu Sep 10, 2009 4:26 pm
Reply with quote

Shanu,
Please check this previous topic.

www.ibmmainframes.com/viewtopic.php?t=30525
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Thu Sep 10, 2009 4:35 pm
Reply with quote

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" icon_biggrin.gif
Back to top
View user's profile Send private message
arvind.m

Active User


Joined: 28 Aug 2008
Posts: 205
Location: Hyderabad

PostPosted: Thu Sep 10, 2009 5:02 pm
Reply with quote

www.ibmmainframes.com/viewtopic.php?t=39153&highlight=
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: Thu Sep 10, 2009 8:46 pm
Reply with quote

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
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