I have taken Mikel's very good idea (combined with some info from IBI support docs) and expanded it a bit to handle the scenario where the job spans more than one calendar day. I have used the TODAY function, since I believe it is dynamically retrieved from the OS when called, whereas I believe the amper date variables are static (please correct me if I am wrong).
I also needed to pass a dummy parameter to function CURRDATE. Does anyone know if FUNCTIONs can take no arguments? (syntax?)
-*--------------------------------------------------------
-* FUNCTION GETTIME
-* Get date and time into format YYYY/MM/DD HH:MM:SS
-* Parameters:
-* DATE: Date in format YYYY/MM/DD
-* TIME: time in format HH.MM.SS
-*--------------------------------------------------------
DEFINE FUNCTION GETTIME(DATE/A10, TIME/A8)
TIMEFMT/A8 = EDIT(TIME, '99$:99$:99');
GETTIME/A20 = DATE | ' ' | TIMEFMT;
END
-*--------------------------------------------------------
-* FUNCTION CURRDATE
-* Get current date from OS (in format MM/DD/YYYY)
-* Parameters:
-* X: Dummy
-*--------------------------------------------------------
DEFINE FUNCTION CURRDATE(X/A1)
DAY/A10 = TODAY(DAY);
YR/A4 = EDIT(DAY, '$$$$$$9999');
MN/A2 = EDIT(DAY, '99$$$$$$$$');
DY/A2 = EDIT(DAY, '$$$99$$$$$');
CURRDATE/A10 = YR | '/' | MN | '/' | DY;
END
-*--------------------------------------------------------
-* FUNCTION ELAPSED
-* Find time difference (in seconds) between a start date
-* and an end date
-* Parameters:
-* STARTTIME: Start datetime in format YYYY/MM/DD HH:MM:SS
-* ENDTIME : End datetime in format YYYY/MM/DD HH:MM:SS
-*--------------------------------------------------------
DEFINE FUNCTION ELAPSED(STARTTIME/A20, ENDTIME/A20)
DATE_TIME1/HYYMDSA=HINPUT(20,STARTTIME,10,'HYYMDS');
DATE_TIME2/HYYMDSA=HINPUT(20,ENDTIME,10,'HYYMDS');
-* THESE ARE THE LINES YOU NEED
-* ESTABLISH THE CONSTANTS FOR HOURS/MIN/SEC PER DAY
SEC_PER_HR/I5=60 * 60;
SEC_PER_DAY/I5=SEC_PER_HR * 24;
-*SUBTRACT THE TWO TIME STAMPS, GETTING DIFFERENCE IN SECONDS
DIFF_SEC/D12.2=HDIFF(DATE_TIME2, DATE_TIME1, 'SECOND', 'D12.2');
-*GET THE DIFF IN WHOLE DAYS
DAYS/I3=IF DIFF_SEC LT SEC_PER_DAY THEN 0 ELSE DIFF_SEC/SEC_PER_DAY ;
-*GET THE DIFF IN WHOLE HOURS
HOURS/I2= IF DAYS NE 0 THEN (DIFF_SEC - (DAYS * SEC_PER_DAY))/SEC_PER_HR ELSE
DIFF_SEC /SEC_PER_HR;
-*GET THE DIFF IN WHOLE MIN
MINT/I2=IF DAYS NE 0 THEN (DIFF_SEC - (DAYS * SEC_PER_DAY + HOURS *
SEC_PER_HR))/60
ELSE (DIFF_SEC - (HOURS * SEC_PER_HR))/60;
-*GET THE DIFF IN WHOLE SEC
SEC/I2=IF DAYS NE 0 THEN DIFF_SEC - ((DAYS * SEC_PER_DAY) + (HOURS *
SEC_PER_HR) + (MINT * 60))
ELSE DIFF_SEC - ((HOURS * SEC_PER_HR) + (MINT * 60)) ;
-*PUT IT TOGETHER
ELAPSED/I10 = (DAYS*24*60*60) + (HOURS*60*60) + (MINT*60) + SEC;
END
-RUN
-* Get starting time of job
-SET &START = GETTIME(CURRDATE('X'), HHMMSS('A8'));
-* -SET &START = GETTIME('2004/07/06', HHMMSS('A8'));
-* Do all your work here (simulated with empty repeat loop)
-REPEAT LABEL1 250000 TIMES
-LABEL1
-* Get ending time of job
-SET &END = GETTIME(CURRDATE('X'), HHMMSS('A8'));
-* Find elapsed time
-SET &ELAPSED = ELAPSED(&START, &END);
-TYPE Elapsed Time (in seconds): &ELAPSED
------------------------------------------------------------------------
PROD: WebFOCUS 7.6.2 on Unix AIX/Tomcat/Servlet Mode
TEST: WebFOCUS 7.6.2 on Unix AIX/Tomcat/Servlet Mode