MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TIMESTAMP Difference

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
nbdtrjk1
Beginner


Joined: 12 Apr 2007
Posts: 76
Topics: 41

PostPosted: Tue Nov 13, 2007 6:58 am    Post subject: TIMESTAMP Difference Reply with quote

I have two Timestamp variables as below. I need to find out the difference (WS-TIMESTAMP2
Back to top
View user's profile Send private message
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Tue Nov 13, 2007 10:33 am    Post subject: Reply with quote

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


Joined: 02 May 2007
Posts: 202
Topics: 0
Location: Viginia, USA

PostPosted: Tue Nov 13, 2007 10:55 am    Post subject: Reply with quote

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


Joined: 08 Aug 2007
Posts: 291
Topics: 2
Location: Chicago

PostPosted: Tue Nov 13, 2007 12:02 pm    Post subject: Reply with quote

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
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Tue Nov 13, 2007 12:53 pm    Post subject: Reply with quote

nbdtrjk1,

Look at this topic.

http://www.mvsforums.com/helpboards/viewtopic.php?t=2261

The last option discusses about timestamp difference in seconds
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
jsharon1248
Intermediate


Joined: 08 Aug 2007
Posts: 291
Topics: 2
Location: Chicago

PostPosted: Tue Nov 13, 2007 1:30 pm    Post subject: Reply with quote

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


Joined: 08 Aug 2007
Posts: 291
Topics: 2
Location: Chicago

PostPosted: Tue Nov 13, 2007 5:21 pm    Post subject: Reply with quote

bonk My apologies Kolusu, I misinterpreted your response. bonk

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


Joined: 12 Apr 2007
Posts: 76
Topics: 41

PostPosted: Wed Nov 14, 2007 3:47 am    Post subject: Reply with quote

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


Joined: 20 Apr 2006
Posts: 222
Topics: 24

PostPosted: Wed Nov 14, 2007 4:06 am    Post subject: Reply with quote

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


Joined: 12 Apr 2007
Posts: 76
Topics: 41

PostPosted: Wed Nov 14, 2007 4:35 am    Post subject: Reply with quote

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


Joined: 20 Apr 2006
Posts: 222
Topics: 24

PostPosted: Wed Nov 14, 2007 8:16 am    Post subject: Reply with quote

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


Joined: 08 Aug 2007
Posts: 291
Topics: 2
Location: Chicago

PostPosted: Wed Nov 14, 2007 9:36 am    Post subject: Reply with quote

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


Joined: 12 Apr 2007
Posts: 76
Topics: 41

PostPosted: Wed Nov 14, 2007 11:20 pm    Post subject: Reply with quote

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


Joined: 20 Apr 2006
Posts: 222
Topics: 24

PostPosted: Thu Nov 15, 2007 2:19 am    Post subject: Reply with quote

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


Joined: 08 Aug 2007
Posts: 291
Topics: 2
Location: Chicago

PostPosted: Thu Nov 15, 2007 9:25 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group