Focal Point
HOW TO DISPLAY SECONDS TO HH:MM:SS

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

October 24, 2007, 02:54 PM
JOE
HOW TO DISPLAY SECONDS TO HH:MM:SS
I have a field that shows time in seconds. Is there a way to convert this field to hh:mm:ss plus also add a negative sign where needed. Ex -00:02:00 = 2 minutes late on a shift.

Thanks for any help

Joe


WebFocus 7.7.02 WinXP
October 24, 2007, 03:11 PM
Prarie
there are probably better ways...but I've used this in the past.

DEFINE FILE CAR
NUMSEC/I4 = 244;
HOUR/I2 = (NUMSEC/60) ;
MIN/I2 = ((NUMSEC/60 - (HOUR *60)));
HHMMSS/I6= INT( NUMSEC/3600 ) * 10000
+ INT( IMOD(NUMSEC,3600,'I4')/60 ) * 100 +
IMOD(NUMSEC,60,'I2');
TIME/A8=EDIT(HHMMSS,'99:99:99');
END
TABLE FILE CAR
PRINT CAR
TIME
END


In Focus since 1993. WebFOCUS 7.7.03 Win 2003
Thanks,
I tried your ex. but still did not get correct results. For ex., one of the records has -60.00 seconds for the time value. I got 00:00:00 instead of getting -00:01:00.

Here's my code:

DEFINE FILE TBLARCH
NUMSEC/I4 = START;
HOUR/I2 = (NUMSEC/3600);
MIN/I2 = ((NUMSEC/24 - (HOUR *60)));
HHMMSS/I6= INT( NUMSEC/3600 ) * 10000 + INT( IMOD(NUMSEC,3600,'I4')/60 ) * 100 + IMOD(NUMSEC,60,'I2');
TIME/A8=EDIT(HHMMSS,'99:99:99');

END

TABLE FILE TBLARCH
SUM
START
TIME
STOP
SCHEDULED
SIGNED_IN
COMPLIANCE

BY EMP_SHORT_NAME

Thanks for any assistance possible.


WebFocus 7.7.02 WinXP
Joe,

Prarie's example works fine; you didn't mention that the values were negatives, so, just add:

NUMSEC/I4 = IF START LT 0 THEN START * (-1) ELSE START;

Also, if you always want to display as a negative:

TIME/A9= '-' | EDIT(HHMMSS,'99:99:99');


Tom Flynn
WebFOCUS 8.1.05 - PROD/QA
DB2 - AS400 - Mainframe
This works for positive numbers, I'm still trying to work out negative numbers.

DEFINE FILE CAR
NBR_SECONDS/D8 =
IF COUNTRY EQ 'ENGLAND'       THEN -60 ELSE
IF COUNTRY EQ 'FRANCE'        THEN 456666 ELSE
IF COUNTRY EQ 'ITALY'         THEN 127 ELSE
IF COUNTRY EQ 'W GERMANY'     THEN 180 ELSE
IF COUNTRY EQ 'JAPAN'         THEN -1 ELSE 481;

CURR_DATE/HHIS = HINPUT(14, '&YYMD.000000', 8, 'HYYMDS');
POS_DATE/HHIS = IF NBR_SECONDS GE 0 THEN HADD(CURR_DATE, 'SECOND', NBR_SECONDS, 8, 'HYYMDS') ELSE CURR_DATE;
END
-RUN

TABLE FILE CAR
PRINT
NBR_SECONDS
POS_DATE
BY COUNTRY
END
-RUN

Joe, what version are you on? Perhaps you could update you signature, as per this request: Friendly reminder: Please update your signatures
[/code]


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
Just for clarification, the only way to display what you want is in string format. There is no concept of negative time (only in the Twilight Zone) so any timestamp format would not work - it can't display -60 seconds. A combination of Prarie's code and Tom's addition for the negative will be what you're looking for. You'll first have to make seconds positive then add the negative after making calculations.


Regards,

Darin



In FOCUS since 1991
WF Server: 7.7.04 on Linux and Z/OS, ReportCaster, Self-Service, MRE, Java, Flex
Data: DB2/UDB, Adabas, SQL Server Output: HTML,PDF,EXL2K/07, PS, AHTML, Flex
WF Client: 77 on Linux w/Tomcat
quote:
WebFOCUS 7.6.1 Win 2003

Thanks,

I'm going to try Tom's suggestion. I think I can make that work.

Joe


WebFocus 7.7.02 WinXP