Focal Point
[SOLVED] Milliseconds to Minutes and Seconds

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/4537037876

October 05, 2015, 01:18 PM
GavinL
[SOLVED] Milliseconds to Minutes and Seconds
Ok, I thought I had it, until I found out that HDIFF is rounding for MINUTE.. The report took 33 seconds to run, but HDIFF is coming back that MINUTE = 1 and SECOND = 33. ???

So when I report the time, I get...

Results
Started On: 2015-10-05 13:12:56.171
Finished On: 2015-10-05 13:13:29.660
Total Report Time: 1m -27s

Code
-SET &NOW = HGETC(8, 'HYYMD-s');
-SET &CHKMIN = (HDIFF(&NOW, &STARTTIME, 'MINUTE', 'D8'));
-SET &CHKSEC = (HDIFF(&NOW, &STARTTIME, 'SECOND', 'D8'));
-SET &CHKSEC = (&CHKSEC-(&CHKMIN*60));

-SET &TIMEDIF  = '&CHKMIN.EVALm &CHKSEC.EVALs';

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



- FOCUS Man, just FOCUS!
-----------------------------
Product: WebFOCUS
Version: 8.1.04
Server: Windows 2008 Server
October 05, 2015, 01:26 PM
GavinL
This seems to be working, but this is redonkulous.

-SET &CHKSEC = IF (&CHKSEC-(&CHKMIN*60)) LT 0 THEN (&CHKSEC-((&CHKMIN-1)*60)) ELSE (&CHKSEC-(&CHKMIN*60));




- FOCUS Man, just FOCUS!
-----------------------------
Product: WebFOCUS
Version: 8.1.04
Server: Windows 2008 Server
October 05, 2015, 02:17 PM
Francis Mariani
This is how I calculate the elapsed time between two Dialogue Manager Date/Time variables. Actually they're two Date and Time pairs of variables, &ST_DATE,&ST_TIME, &EN_DATE,&EN_TIME. This might be overkill...

-*-- Set Report End Date and Time
-SET &EN_DATE = &YYMD;
-SET &EN_TIME = EDIT(HHMMSS('A8'),'99$99$99');

-SET &EN_DATEX = EDIT(&EN_DATE,'9999/99/99');
-SET &EN_TIMEX = EDIT(&EN_TIME,'99:99:99');

-*-- Calculate Report Elapsed Time
-SET &DTTM1 = HINPUT(14, '&ST_DATE.EVAL&ST_TIME.EVAL', 14, 'HYYMDS');
-SET &DTTM2 = HINPUT(14, '&EN_DATE.EVAL&EN_TIME.EVAL', 14, 'HYYMDS');

-SET &ELAPSED_S = HDIFF(&DTTM2, &DTTM1, 'SECOND', 'D12');

-SET &ELAPSED_H  = &ELAPSED_S / 3600;
-SET &ELAPSED_MR = FMOD(&ELAPSED_S, 3600, 'F2');

-SET &ELAPSED_M = &ELAPSED_MR / 60;
-SET &ELAPSED_SR = FMOD(&ELAPSED_MR, 60, 'F2');

-SET &ELAPSED_H  = FPRINT(&ELAPSED_H,  'I4',  'A4');
-SET &ELAPSED_M  = FPRINT(&ELAPSED_M,  'I2L', 'A2');
-SET &ELAPSED_SR = FPRINT(&ELAPSED_SR, 'I2L', 'A2');

-SET &ELAPSED_TIME = &ELAPSED_H || 'h' || (' ' | &ELAPSED_M) || 'm' || (' ' | &ELAPSED_SR) || 's';

-TYPE Program Elapsed Time: &ELAPSED_TIME




Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
October 05, 2015, 02:57 PM
GavinL
I'm having to do this a lot within a report as I'm timing webservices, so I'm attempting to keep the code down to a minimum.

At the same time though, I'm going to look at FMOD a little closer to see if that is something I can use.

Thanks for the input.



- FOCUS Man, just FOCUS!
-----------------------------
Product: WebFOCUS
Version: 8.1.04
Server: Windows 2008 Server
October 05, 2015, 05:23 PM
Waz
Another option here is to use a DEFINE FUNCTION.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

October 06, 2015, 06:49 AM
Tony A
Gavin,

Check out this post.

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
October 06, 2015, 12:19 PM
GavinL
quote:
Check out this post.


Right on.. I attempted to use it, but it looks like I can't run it via console, which is where this will always be ran. I'll play around with it when I get a little more time to make it usable for console.

Thanks.



- FOCUS Man, just FOCUS!
-----------------------------
Product: WebFOCUS
Version: 8.1.04
Server: Windows 2008 Server
October 06, 2015, 12:33 PM
Tony A
A quick mod to allow alpha input -

DEFINE FUNCTION HTIMEDIFF(ENDTIME/A23, BEGTIME/A23)
  D_TIMEBEG/HYYMDs = HINPUT(23, BEGTIME, 8, 'HYYMDs');
  D_TIMEEND/HYYMDs = HINPUT(23, ENDTIME, 8, 'HYYMDs');
  D_DIFF/D12.2  = HDIFF(D_TIMEEND, D_TIMEBEG, 'MILLISECONDS', 'D12.2');
  D_DAYS/I2L    = INT(D_DIFF / 86400000);
  D_HOURS/I2L   = INT((D_DIFF - (D_DAYS * 86400000)) / 3600000);
  D_MINS/I2L    = INT((D_DIFF - (D_DAYS * 86400000) - (D_HOURS * 3600000)) / 60000);
  D_SECS/I2L    = INT((D_DIFF - (D_DAYS * 86400000) - (D_HOURS * 3600000) - (D_MINS * 60000)) / 1000);
  D_MSECS/I3L   = INT((D_DIFF - (D_DAYS * 86400000) - (D_HOURS * 3600000) - (D_MINS * 60000) - (D_SECS * 1000)));
  HTIMEDIFF/A23 = '        '||EDIT(D_DAYS)||' '|EDIT(D_HOURS)||':'||EDIT(D_MINS)||':'||EDIT(D_SECS)||'.'||EDIT(D_MSECS);
END
-RUN

-SET &Time_Beg = '2015-10-05 13:12:56.171';
-SET &Time_End = '2015-10-05 13:13:29.660';
-SET &Time_Diff = HTIMEDIFF(&Time_End, &Time_Beg);

-? &Time


Good luck.

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
October 06, 2015, 01:11 PM
GavinL
quote:
A quick mod to allow alpha input -

DEFINE FUNCTION HTIMEDIFF(ENDTIME/A23, BEGTIME/A23)
D_TIMEBEG/HYYMDs = HINPUT(23, BEGTIME, 8, 'HYYMDs');
D_TIMEEND/HYYMDs = HINPUT(23, ENDTIME, 8, 'HYYMDs');
D_DIFF/D12.2 = HDIFF(D_TIMEEND, D_TIMEBEG, 'MILLISECONDS', 'D12.2');
D_DAYS/I2L = INT(D_DIFF / 86400000);
D_HOURS/I2L = INT((D_DIFF - (D_DAYS * 86400000)) / 3600000);
D_MINS/I2L = INT((D_DIFF - (D_DAYS * 86400000) - (D_HOURS * 3600000)) / 60000);
D_SECS/I2L = INT((D_DIFF - (D_DAYS * 86400000) - (D_HOURS * 3600000) - (D_MINS * 60000)) / 1000);
D_MSECS/I3L = INT((D_DIFF - (D_DAYS * 86400000) - (D_HOURS * 3600000) - (D_MINS * 60000) - (D_SECS * 1000)));
HTIMEDIFF/A23 = ' '||EDIT(D_DAYS)||' '|EDIT(D_HOURS)||':'||EDIT(D_MINS)||':'||EDIT(D_SECS)||'.'||EDIT(D_MSECS);
END
-RUN

-SET &Time_Beg = '2015-10-05 13:12:56.171';
-SET &Time_End = '2015-10-05 13:13:29.660';
-SET &Time_Diff = HTIMEDIFF(&Time_End, &Time_Beg);

-? &Time


Your alright, no matter what everyone else says about you. :P



- FOCUS Man, just FOCUS!
-----------------------------
Product: WebFOCUS
Version: 8.1.04
Server: Windows 2008 Server
October 06, 2015, 01:32 PM
Tony A
quote:
no matter what everyone else says about you.

We all have our burdens to bear! Wink

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10