View previous topic :: View next topic
|
Author |
Message |
dejunzhu
Active User
Joined: 08 May 2008 Posts: 390 Location: China
|
|
|
|
I wonder if COBOL support the function of addition and subtraction of dates.
for example, given a day, say 20120315, if I add 16 to this date, the result becomes 20120401 (April the 1st)
Help need on this. Thanks for your reply! |
|
Back to top |
|
|
krishna_ragav
New User
Joined: 29 Oct 2010 Posts: 10 Location: Chennai
|
|
|
|
Hi,
As per my knowledge there are no statement which can calculate and produce proper date by COBOL.
Most of application would have separate date routine to calculate/ adjust the dates.
Regards,
Krishna |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Have a look at the manuals for the list of Intrinsic Functions.
Language Environment also provides callable services. |
|
Back to top |
|
|
Peter cobolskolan
Active User
Joined: 06 Feb 2012 Posts: 104 Location: Sweden
|
|
|
|
There is nothing than programming that solves the problem.
I recommend You read about COBOL Intrinsic Functions and date-functions.
Here is a small program example:
Code: |
Identification Division.
Program-Id. DATENEXT.
Data Division.
Working-Storage Section.
77 TodaysDate Pic 9(08).
77 IntTodaysDate Pic 9(07).
77 NextDate Pic 9(08).
77 IntNextDate Pic 9(07).
77 DayInterval Pic 9(02) Value 15.
Procedure Division.
Move Function CURRENT-DATE(1:8) to TodaysDate
Compute IntNextDate =
Function INTEGER-OF-DATE(TodaysDate) + DayInterval
End-Compute
Compute NextDate =
Function DATE-OF-INTEGER(IntNextDate)
End-Compute
Display 'The date ' DayInterval
' days from ' TodaysDate
' is ' NextDate
GoBack
. |
|
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
If dejunzhu means direct manipulaiton of date-type variables in COBOL, then the answer is no, COBOL doesn't support them. If, however, dejunzhu just wants to manipulate dates, then the answer is yes, COBOL supports intrinsic functions that allow conversion of dates into integers, after which addition and subtraction is easy, as is using the intrinsic function to convert the integer back into a date.
Krishna, your answer is SEVERAL years out of date -- the intrinsic functions were added to COBOL quite a while back. |
|
Back to top |
|
|
krishna_ragav
New User
Joined: 29 Oct 2010 Posts: 10 Location: Chennai
|
|
|
|
Thank You Robert. |
|
Back to top |
|
|
UmeySan
Active Member
Joined: 22 Aug 2006 Posts: 771 Location: Germany
|
|
|
|
@ Peter cobolskolan
Morning Sir, Ursäkta mig !
Seams, that it does not work:
MOVE FUNCTION CURRENT-DATE(1:8) TO TODAYSDATE
COMPUTE INTNEXTDATE =
FUNCTION INTEGER-OF-DATE(TODAYSDATE) + DAYINTERVAL
END-COMPUTE
COMPUTE NEXTDATE =
FUNCTION DATE-OF-INTEGER(INTNEXTDATE)
END-COMPUTE
XPEDITER/TSO - SOURCE :
01 TODAYSDATE > 20120315
01 DAYINTERVAL > 03
01 NEXTDATE > 20120330 -> 15+03=18
Did i made something wrong, just following your instructions ???
Jag förstår inte.
Hjärtligt tack! |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
That's odd. My code is
Code: |
01 WS-CURRENT-DATE.
05 WS-CD PIC 9(08).
05 PIC X(13).
01 WS-INT-DATE PIC 9(07).
01 WS-DAYINTERVAL PIC 9(07) VALUE 3.
01 WS-OUTPUT-DATE PIC 9(08).
PROCEDURE DIVISION.
S1000-MAIN SECTION.
MOVE FUNCTION CURRENT-DATE TO WS-CURRENT-DATE.
DISPLAY 'CURRENT DATE: ' WS-CURRENT-DATE.
COMPUTE WS-INT-DATE =
FUNCTION INTEGER-OF-DATE (WS-CD) .
DISPLAY 'INTEGER VALUE: ' WS-INT-DATE.
ADD WS-DAYINTERVAL TO WS-INT-DATE.
DISPLAY 'INTEGER VALUE: ' WS-INT-DATE.
COMPUTE WS-OUTPUT-DATE =
FUNCTION DATE-OF-INTEGER (WS-INT-DATE) .
DISPLAY 'OUTPUT DATE: ' WS-OUTPUT-DATE. |
and it produces output of
Code: |
CURRENT DATE: 2012031509093382-0400
INTEGER VALUE: 0150189
INTEGER VALUE: 0150192
OUTPUT DATE: 20120318 |
|
|
Back to top |
|
|
UmeySan
Active Member
Joined: 22 Aug 2006 Posts: 771 Location: Germany
|
|
|
|
@Peter cobolskolan
@Robert Sample
I just found out, that only playing with the interval-field during XPEDITER-session seams to be the problem. The first time, the calculation is done, everything's correct. Now, when i go back to re-run the calculation after chanching the value of the interval-field nothing is realy recalculated.
Only a new program-generation (compile/link) with a new value in the interval-field, will give a new correct result in the nextdate-field?
Holy smoke, seams to be very misterious. I wonder if the iluminati have a finger in the pie. |
|
Back to top |
|
|
|