Let's Get Social!
Focal Point    Focal Point Forums    WebFOCUS/FOCUS Forum on Focal Point     [CLOSED] Calculate Total Time Run
 Go New Search Notify Tools Reply
 [CLOSED] Calculate Total Time Run
Member
 posted April 16, 2019 02:11 PM
Hello all,

I have two fields I am working with here.. Batch_ID and Time_Run

Ex:

Batch_ID Time_Run
A123 04/12/2019 14:15:33.347
A123 04/12/2019 15:20:17.167
B567 04/13/2019 10:07:12.016
B567 04/13/2019 10:15:18.245
B567 04/13/2019 10:17:33.300
B567 04/13/2019 10:35:43.187
CC257 04/15/2019 04:00:33.067
CC257 04/15/2019 04:48:28.467

I would like to calculate how long did it take to run a Batch job. I know I can use HDIFF to calculate the difference between two dates but how do I get difference when working with one one date column?

For Ex: Duration for Batch_ID A123 in hours is 1, in minutes is 64, and in seconds is 3884

This message has been edited. Last edited by: FP Mod Chuck,

WebFOCUS 8
Windows, All Outputs

 Posts: 28 | Registered: September 05, 2017 IP
Virtuoso
 posted April 16, 2019 02:21 PM Hide Post
What is the duration for batch id B567? Are you just comparing the first batch id to the last one? If that's the case, you should:
1. Make sure the data is sorted by Batch ID.
2. Use LAST syntax to find the last batch id and flag it so you know what two values have to be subtracted to get the difference.

Ideally, your database would have a START and END date times so you could avoid all this because you'll also have to account for when the clock resets from 23:59 to 0:00 at midnight and if your times are split between two dates, your calculation would have to account for that.

HDIFF doc has an example specific to time in the bottom of the page https://webfocusinfocenter.inf...ver/source/htime.htm

This message has been edited. Last edited by: BabakNYC,

WebFOCUS 8206, Unix, Windows

 Posts: 1788 | Location: New York City | Registered: December 30, 2015 IP
Virtuoso
 posted April 18, 2019 04:26 AM Hide Post
I would suggest a multi-verb for calculating the difference between a batch's earliest and last timestamps. Off the top of my head:
```TABLE FILE X
SUM
MIN.Time_Run
MAX.Time_Run
COMPUTE Time_Spent/I10 = HDIFF(MAX.Time_Run, MIN.Time_Run, 'SECOND', Time_Spent);
BY Batch_ID
PRINT
COMPUTE Step_Time/I10  = HDIFF(Time_Run, LAST Time_Run, 'SECOND', Step_Time);
BY Batch_ID
BY Time_Run NOPRINT
END```

You probably want to special-case the first row of Step_Time though, as you'll get a huge number otherwise (Batch start time - basedate:'1900/12/31').

WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :

 Posts: 1655 | Location: Enschede, Netherlands | Registered: August 12, 2010 IP