View previous topic :: View next topic |
Author |
Message |
nbdtrjk1 Beginner
Joined: 12 Apr 2007 Posts: 76 Topics: 41
|
Posted: Tue Nov 13, 2007 6:58 am Post subject: TIMESTAMP Difference |
|
|
I have two Timestamp variables as below. I need to find out the difference (WS-TIMESTAMP2 |
|
Back to top |
|
 |
dbzTHEdinosauer Supermod
Joined: 20 Oct 2006 Posts: 1411 Topics: 26 Location: germany
|
Posted: Tue Nov 13, 2007 10:33 am Post subject: |
|
|
well, first of all, your 14 byte areas are not timestamps............
second, if you look at some of the earlier mainframe challanges, kolusu has a topic about cobol date arithmetic, and that is what you need. _________________ Dick Brenholtz
American living in Varel, Germany |
|
Back to top |
|
 |
CraigG Intermediate
Joined: 02 May 2007 Posts: 202 Topics: 0 Location: Viginia, USA
|
Posted: Tue Nov 13, 2007 10:55 am Post subject: |
|
|
dbzTHEdinosauer wrote: | well, first of all, your 14 byte areas are not timestamps............
second, if you look at some of the earlier mainframe challanges, kolusu has a topic about cobol date arithmetic, and that is what you need. |
He never claimed they were DB2 timestamps. |
|
Back to top |
|
 |
jsharon1248 Intermediate
Joined: 08 Aug 2007 Posts: 291 Topics: 2 Location: Chicago
|
Posted: Tue Nov 13, 2007 12:02 pm Post subject: |
|
|
I'd recommend using LE conversion services. Convert each timestamp to a floating point value using CEESECS. Subtract them. Then use CEEDATM to convert the result back to a timestamp. Check out Chapter 22, Using Date and Time Services in the LE Programming Guide.
http://publibz.boulder.ibm.com/epubs/pdf/ceea2030.pdf
If for some reason you can't get that to work, convert the timestamps to DB2 timestamps and use SQL to subtract the timestamps. I wouldn't add SQL to a program that doesn't already have it, but if the program already issues SQL, then this would be an option too. |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
|
Back to top |
|
 |
jsharon1248 Intermediate
Joined: 08 Aug 2007 Posts: 291 Topics: 2 Location: Chicago
|
Posted: Tue Nov 13, 2007 1:30 pm Post subject: |
|
|
True, the CEESECS LE service converts the timestamps to seconds and the COBOL code will calculate the difference in seconds. But one more call to the CEEDATM LE service converts the result from seconds to a character timestamp format which is what the op requested. As long as the timestamps are between Oct 15, 1582 00:00:01 and Dec 31, 9999 23:59:59, the LE services can and should be used for date/time arithmetic.
I should have posted the link for the LE Programming Reference too. The LE Programming Guide doesn't give all the details for the calls.
http://publibz.boulder.ibm.com/epubs/pdf/ceea3031.pdf |
|
Back to top |
|
 |
jsharon1248 Intermediate
Joined: 08 Aug 2007 Posts: 291 Topics: 2 Location: Chicago
|
Posted: Tue Nov 13, 2007 5:21 pm Post subject: |
|
|
My apologies Kolusu, I misinterpreted your response.
One final note. Durations can be very tricky when you start mixing in months. When I used durations in the past, I would convert to days. You can mix in hours, minutes and seconds, but months and years can add confusion because they're not constants. |
|
Back to top |
|
 |
nbdtrjk1 Beginner
Joined: 12 Apr 2007 Posts: 76 Topics: 41
|
Posted: Wed Nov 14, 2007 3:47 am Post subject: |
|
|
Hi All
I coded as per Kolusu's link
IDENTIFICATION DIVISION.
PROGRAM-ID. BBBB.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-PICSTR.
02 WS-LEN PIC S9(04) COMP.
02 WS-OUT-TEXT.
03 WS-OUT-STR PIC X
OCCURS 0 TO 256 TIMES
DEPENDING ON WS-LEN.
01 WS-NEW-TIMESTAMP PIC X(80).
01 WS-SECOND1 COMP-2.
01 WS-SECOND2 COMP-2.
01 WS-SECOND3 COMP-2.
01 WS-TIMESTAMP-1 PIC X(26).
01 WS-TIMESTAMP-2 PIC X(26).
01 WS-FORMAT PIC X(26).
01 WS-DIFFERENCE PIC +9(09).
01 WS-FC-CODE.
05 FC-SEVERITY PIC S9(4) COMP.
05 FC-MESSAGE PIC S9(4) COMP.
05 FILLER PIC X(08).
PROCEDURE DIVISION.
MAIN-PARA.
MOVE '2004-03-23 20.37.39.838149' TO WS-TIMESTAMP-1
MOVE '2004-03-24 21.38.39.838149' TO WS-TIMESTAMP-2
MOVE 'YYYY-MM-DD HH.MI.SS.999999' TO WS-FORMAT
CALL 'CEESECS' USING WS-TIMESTAMP-1,
WS-FORMAT,
WS-SECOND1,
WS-FC-CODE
IF FC-SEVERITY = +0
CONTINUE
ELSE
DISPLAY 'CEESECS ROUTINE ERROR'
END-IF
CALL 'CEESECS' USING WS-TIMESTAMP-2,
WS-FORMAT,
WS-SECOND2,
WS-FC-CODE
IF FC-SEVERITY = +0
CONTINUE
ELSE
DISPLAY 'CEESECS ROUTINE ERROR'
END-IF
COMPUTE WS-DIFFERENCE = WS-SECOND2 - WS-SECOND1
MOVE WS-DIFFERENCE TO WS-SECOND3
DISPLAY 'THE DIFFERENCE BETWEEN 2 TIMESTAMPS IS:'
WS-DIFFERENCE ':' WS-SECOND3
MOVE +26 TO WS-LEN
MOVE 'YY-MM-DD HH.MI.SS.999999' TO WS-OUT-TEXT
CALL 'CEEDATM' USING WS-SECOND3,
WS-PICSTR,
WS-NEW-TIMESTAMP,
WS-FC-CODE
IF FC-SEVERITY = 00
DISPLAY 'THE NEW TIMESTAMP IS : ' WS-NEW-TIMESTAMP
ELSE
DISPLAY 'THE CEEDATM CALL FAILED WITH : ' FC-SEVERITY
END-IF
STOP RUN.
For the above code i got below o/p
THE DIFFERENCE BETWEEN 2 TIMESTAMPS IS:+000090060: .90060000000000000E 05
THE NEW TIMESTAMP IS : 82-10-15 01.01.00.000000
but this is worng output.. please help me whether above code logic is correct or not |
|
Back to top |
|
 |
vivek1983 Intermediate

Joined: 20 Apr 2006 Posts: 222 Topics: 24
|
Posted: Wed Nov 14, 2007 4:06 am Post subject: |
|
|
nbdtrjk1,
Use bbcode to show the code in a better understandable format. _________________ Vivek G
--------------------------------------
A dream is just a dream. A goal is a dream with a plan and a deadline. (Harvey Mackay) |
|
Back to top |
|
 |
nbdtrjk1 Beginner
Joined: 12 Apr 2007 Posts: 76 Topics: 41
|
Posted: Wed Nov 14, 2007 4:35 am Post subject: |
|
|
Hi All
I coded as per Kolusu's link
Code: | IDENTIFICATION DIVISION.
PROGRAM-ID. BBBB.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-PICSTR.
02 WS-LEN PIC S9(04) COMP.
02 WS-OUT-TEXT.
03 WS-OUT-STR PIC X
OCCURS 0 TO 256 TIMES
DEPENDING ON WS-LEN.
01 WS-NEW-TIMESTAMP PIC X(80).
01 WS-SECOND1 COMP-2.
01 WS-SECOND2 COMP-2.
01 WS-SECOND3 COMP-2.
01 WS-TIMESTAMP-1 PIC X(26).
01 WS-TIMESTAMP-2 PIC X(26).
01 WS-FORMAT PIC X(26).
01 WS-DIFFERENCE PIC +9(09).
01 WS-FC-CODE.
05 FC-SEVERITY PIC S9(4) COMP.
05 FC-MESSAGE PIC S9(4) COMP.
05 FILLER PIC X(08).
PROCEDURE DIVISION.
MAIN-PARA.
MOVE '2004-03-23 20.37.39.838149' TO WS-TIMESTAMP-1
MOVE '2004-03-24 21.38.39.838149' TO WS-TIMESTAMP-2
MOVE 'YYYY-MM-DD HH.MI.SS.999999' TO WS-FORMAT
CALL 'CEESECS' USING WS-TIMESTAMP-1,
WS-FORMAT,
WS-SECOND1,
WS-FC-CODE
IF FC-SEVERITY = +0
CONTINUE
ELSE
DISPLAY 'CEESECS ROUTINE ERROR'
END-IF
CALL 'CEESECS' USING WS-TIMESTAMP-2,
WS-FORMAT,
WS-SECOND2,
WS-FC-CODE
IF FC-SEVERITY = +0
CONTINUE
ELSE
DISPLAY 'CEESECS ROUTINE ERROR'
END-IF
COMPUTE WS-DIFFERENCE = WS-SECOND2 - WS-SECOND1
MOVE WS-DIFFERENCE TO WS-SECOND3
DISPLAY 'THE DIFFERENCE BETWEEN 2 TIMESTAMPS IS:'
WS-DIFFERENCE ':' WS-SECOND3
MOVE +26 TO WS-LEN
MOVE 'YY-MM-DD HH.MI.SS.999999' TO WS-OUT-TEXT
CALL 'CEEDATM' USING WS-SECOND3,
WS-PICSTR,
WS-NEW-TIMESTAMP,
WS-FC-CODE
IF FC-SEVERITY = 00
DISPLAY 'THE NEW TIMESTAMP IS : ' WS-NEW-TIMESTAMP
ELSE
DISPLAY 'THE CEEDATM CALL FAILED WITH : ' FC-SEVERITY
END-IF
STOP RUN. |
For the above code i got below o/p
THE DIFFERENCE BETWEEN 2 TIMESTAMPS IS:+000090060: .90060000000000000E 05
THE NEW TIMESTAMP IS : 82-10-15 01.01.00.000000
but this is worng output.. please help me whether above code logic is correct or not |
|
Back to top |
|
 |
vivek1983 Intermediate

Joined: 20 Apr 2006 Posts: 222 Topics: 24
|
Posted: Wed Nov 14, 2007 8:16 am Post subject: |
|
|
nbdtrjk1,
Quote: |
THE DIFFERENCE BETWEEN 2 TIMESTAMPS IS:+000090060: .90060000000000000E 05
|
While calculating manaully I get the above difference in seconds.
The problem here is that you are trying to convert the "difference in seconds" to timestamp using CEEDATM call. But as per the definition:
"CEEDATM converts a number representing the number of seconds since 00:00:00 14 October 1582 to a character string format. "
Meaning CEEDATM converts seconds in lilian format to timestamp. In your code, you are not converting the seconds in lilian format.
Seconds in lilian format is :
the number of seconds since 00:00:00 14 October 1582.
There must be some way to convert the difference in seconds into lilian format before calling the CEEDATM.
Hope I am not missing anything. _________________ Vivek G
--------------------------------------
A dream is just a dream. A goal is a dream with a plan and a deadline. (Harvey Mackay) |
|
Back to top |
|
 |
jsharon1248 Intermediate
Joined: 08 Aug 2007 Posts: 291 Topics: 2 Location: Chicago
|
Posted: Wed Nov 14, 2007 9:36 am Post subject: |
|
|
I know I brought it up, but CEEDATM will not help you. CEEDATM should be used when adding durations to timestamps, not when computing the duration between timestamps.
That being said, I'm not sure that computing the duration between timestamps and then converting that duration to a timestamp is such a good idea. The variable nature of number of days in months and number of days in years makes interpreting a timestamp as a duration confusing at best. What if your duration is 89 days? What would you want in your timestamp? 89 days into the year would be 3/30. Somehow that doesn't seem right. Using 30 days per month, 89 days is actually 2 months and 29 days. Would you want to see 2/29 in your timestamp? That's not a valid date for non-leap years, so would you want to see 3/1?
I think a better method would be to convert the duration from seconds to days, hours, minutes, and seconds. Days, hours, minutes, and seconds do not vary and will reduce confusion when discussing duration. |
|
Back to top |
|
 |
nbdtrjk1 Beginner
Joined: 12 Apr 2007 Posts: 76 Topics: 41
|
Posted: Wed Nov 14, 2007 11:20 pm Post subject: |
|
|
I am expecting below output.
Code: | THE NEW TIMESTAMP IS : 00-00-01 01.01.00.000000 |
How to convert the difference in seconds into lilian format before calling CEEDATM? |
|
Back to top |
|
 |
vivek1983 Intermediate

Joined: 20 Apr 2006 Posts: 222 Topics: 24
|
Posted: Thu Nov 15, 2007 2:19 am Post subject: |
|
|
nbdtrjk1,
I would go with jsharon1248's suggestion:
Quote: |
I think a better method would be to convert the duration from seconds to days, hours, minutes, and seconds. Days, hours, minutes, and seconds do not vary and will reduce confusion when discussing duration.
|
_________________ Vivek G
--------------------------------------
A dream is just a dream. A goal is a dream with a plan and a deadline. (Harvey Mackay) |
|
Back to top |
|
 |
jsharon1248 Intermediate
Joined: 08 Aug 2007 Posts: 291 Topics: 2 Location: Chicago
|
Posted: Thu Nov 15, 2007 9:25 am Post subject: |
|
|
I'll apologize one last time for bringing up CEEDATM. It will not help you. The date range for CEEDATM starts at 0ct 15, 1582. It is not like DB2's date range that starts at Jan 1, 0001. The output that CEEDATM is returning in your previous post is correct. You trunacted the century portion, 15, and it shows the year as 82; put them together and you get 1582. The 10/15 date is the lowest date possible. |
|
Back to top |
|
 |
|
|