How to get difference between two current timstamp in cobol



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

How to get difference between two current timstamp in cobol

Postby dkuma14 » Sat Jun 09, 2018 4:25 am

I tried to search any information regarding this before posting here but unfortunately could not found.

Can someone please help on how to calculate difference between two timestamp.

Actually my requiremt is that My job should extract only those records from database which got processed (will be using database current timestamp) after last run of this job (here for last run I will be passing previous job run date as input which is last job run current timestamp).
dkuma14
 
Posts: 18
Joined: Thu Oct 13, 2016 7:34 pm
Has thanked: 8 times
Been thanked: 0 time

Re: How to get difference between two current timstamp in cobol

 

Re: How to get difference between two current timstamp in co

Postby NicC » Sat Jun 09, 2018 4:56 pm

This is not a COBOL problem but an SQL problem which is why you did not find any examples (possibly). Try googling "select records greater than timestamp"
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 2812
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 116 times

Re: How to get difference between two current timstamp in co

Postby dkuma14 » Sat Jun 09, 2018 5:18 pm

Thanks for your response but it is not a db2 database but IMS.And moreover in my approach I need to check difference between two timestamp. One for processed date of transaction (this will be already present in an input file which is actual unload of that database) and second time stamp is of last run of my same job which will execute Cobol and second timestamp will be also coming from my another input file. Hence to summarise when this job run Cobol should consider those records only for processing which have processed date in input 1 after last run time. Right now I am using date format YYYY-MM-DD for processed date and last run. Then using function Integer of date (processed date) - function integer of date(last run) > 0 Then do Cobol logic. It’s working fine technically but it does not complete requirement completely. Suppose my job ran on 8 June around 14 PM , next day when it will run it will process only those records which got processed on 9th June after 00.01 and records which got processed on 8th June after 14 PM will not be processed which is incorrect, those record should also get processed actually.Hence need of comparing two timestamp will help and function Integer of date does not work on timestamp.
dkuma14
 
Posts: 18
Joined: Thu Oct 13, 2016 7:34 pm
Has thanked: 8 times
Been thanked: 0 time

Re: How to get difference between two current timstamp in co

Postby enrico-sorichetti » Sat Jun 09, 2018 5:35 pm

convert the timestamps to seconds/milliseconds/microseconds whatever the timestamp precision dictates
compute the difference
convert the difference to the wanted units representation ...
seconds, minutes, hours, days

after that is just a programming exercise, You will find gazillions of examples googling
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2777
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 147 times

Re: How to get difference between two current timstamp in co

Postby Robert Sample » Sat Jun 09, 2018 7:37 pm

I think terminology is tripping you up. "Timestamp" is a term that has a very specific meaning and I don't think that meaning applies to what you are wanting to do.
Right now I am using date format YYYY-MM-DD for processed date and last run.
Why not have the last run as YYYY-MM-DD HH:MM:SS instead of just YYYY-MM-DD? Then your logic becomes
IF INPUT-DATE > LAST-RUN-DATE
    PROCESS THE RECORD
ELSE
    IF INPUT-DATE = LAST-RUN-DATE
    AND INPUT-TIME > LAST-RUN-TIME
        PROCESS THE RECORD
    END-IF
END-IF
Or you could use the LE run-time functions (such as CEESECS) to convert your date/time sets to Lillian format and compare the Lillian formats.

These users thanked the author Robert Sample for the post:
dkuma14 (Sat Jun 09, 2018 8:26 pm)
Robert Sample
Global moderator
 
Posts: 3525
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 251 times

Re: How to get difference between two current timstamp in co

Postby dkuma14 » Sat Jun 09, 2018 8:26 pm

Thanks Robert for your suggestion. Yes I saw some manual regarding CEESECS , will try it on Monday bcz Right now I can’t access mainframe . Your first approach looks simple and will suffix my requirement, my bad II didn’t think in this way. First I will try this approach. This is below I will do to achieve it, please correct me If I am going wrong.

WS-Processed-DT= 2018-06-08
WS-processed-time= 14:30:12 I will populate these two from my input 1 which have processed timestamp

We-lastrun-dt = 2018-06-08
WA-lastrun-time= 13:30:12. I will populate these two from my input 2 having last run timestamp

IF
WS-processed-dt > ws-lastrun-dt
Process the record
ELSE
IF ws-processed-dt = ws-lastrun-dt
AND ws-processed-time > ws-lastrun-Time
Process the record
END-IF
END-IF


In above scenarios ELSE part will be executed.
dkuma14
 
Posts: 18
Joined: Thu Oct 13, 2016 7:34 pm
Has thanked: 8 times
Been thanked: 0 time


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post