Focal Point
[CLOSED] CONVERTING TIME FROM SECONDS TO HOURS AND MINUTES

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

February 12, 2008, 04:21 PM
LOgle
[CLOSED] CONVERTING TIME FROM SECONDS TO HOURS AND MINUTES
My time field shows as 780, I need this to convert to an HHMM field,ie 1:00 pm. I am able to find converting a date/time filed but this is just a time field. I have tried some of the suggestions on the date/time page but cannot get this to work. Any suggestions?

Thanks!

This message has been edited. Last edited by: <Kathryn Henning>,


V. 762
Windows XP
February 12, 2008, 04:46 PM
FrankDutch
Show what you tried, we can be more specific in the helping.

Obviously your field now is a number.
Is it in seconds?

780/60=13 minutes, so in time like hhmmss 00:13:00.




Frank

prod: WF 7.6.10 platform Windows,
databases: msSQL2000, msSQL2005, RMS, Oracle, Sybase,IE7
test: WF 7.6.10 on the same platform and databases,IE7

February 12, 2008, 04:50 PM
Prarie
WAITSS/I6= INT( AVGWAITS/3600 ) * 10000
+ INT( IMOD(AVGWAITS,3600,'I4')/60 ) * 100 +
IMOD(AVGWAITS,60,'I2');
AVGWAIT/A5=EDIT(WAITSS,'$$99:99');


In Focus since 1993. WebFOCUS 7.7.03 Win 2003
Here is what I tried.

Define file Patient

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');
WHERE APPOINT.APPOINT.FROM EQ TIME;

I did not design the database but go figure the field for the Appt Time is FROM


V. 762
Windows XP
NUMBER (10)
and Yes my original field is a Number field. Thanks!


V. 762
Windows XP
Well, that seems about right to me. I took the code you provided and stuck it in a define for the car database, and the time comes out just fine. My code:
DEFINE FILE CAR
NUMSEC/I4 WITH CAR = 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

For every record it show the time as being 00:04:04, which corresponds perfectly with the 244 that we put into the NUMSEC field.
What exactly is your problem?


GamP

- Using AS 8.2.01 on Windows 10 - IE11.
in Focus since 1988
quote:
DEFINE FILE CAR
NUMSEC/I4 WITH CAR = 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



This is what it returns.
FIRST LAST HOMEAREA HOMEPHONE DATE FROM STATUS TIME
John Doe 615 887-0000 2008/02/15 540 ACTIVE 00:00:00
Jane Doe 615 641-0000 2008/02/15 540 ACTIVE 00:00:00

Here is my Code:

DEFINE FILE PATIENT

THISDAY/YYMD = &YYMD;
TDAY/YYMD = DATEADD(THISDAY, 'BD',2 );

NUMSEC/I4 WITH PATIENT = '';
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 PATIENT
PRINT
'PATIENT.PATIENT.FIRST'
'PATIENT.PATIENT.LAST'
'PATIENT.PATIENT.HOMEAREA'
'PATIENT.PATIENT.HOMEPHONE'
'APPOINT.APPOINT.DATE'
'APPOINT.APPOINT.FROM'
'PATIENT.PATIENT.STATUS'
'TIME'


V. 762
Windows XP
quote:
DEFINE FILE CAR
NUMSEC/I4 WITH CAR = 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


I get 00:04:04 as well (on 5.3.2)


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
Maybe I am not understanding how to do this. I need the time from my field FROM to populate the Converted Time field. The information is in the Field From When I do my report I need the seconds to show up in HHMMSS Where in my code do I need to make the change? Obiously my code will not be NUMSEC/I4 With Car do I need to Put NUMSSEC/I4 With Patient?


V. 762
Windows XP
I am getting closer I put my field FROM in place of the 244 but my time for 780 printed as 00:13:00 and it should print as 1:00 pm


V. 762
Windows XP
Here is some code I have...no time to change to you...but you can get the idea
Surely there is a better way...
TIME1/A6 = EDIT(STARTTIME);
TIMELEFT/A2 = EDIT(TIME1,'$$99$$');
TIMERIGHT/A2 = EDIT(TIME1,'$$$$99');
TIME2/A6 = TIMELEFT | ':' | TIMERIGHT;
HRS1/I2 = EDIT(TIMELEFT);
HRS2/I2 = IF HRS1 GT 12 THEN HRS1 - 12 ELSE HRS1;
AM/A2 = IF HRS1 GE 12 THEN 'PM' ELSE 'AM';
HRS3/A2 = EDIT(HRS2);
NEWTIME/A7 = HRS3 | ':' | TIMERIGHT | AM;
MORETIME/A7 = HRS3 | ':' | '00' | AM;
THISTIME/A7 = IF MORETIME EQ '00:00AM' THEN '12:00AM' ELSE MORETIME;


In Focus since 1993. WebFOCUS 7.7.03 Win 2003
Here's another method, using Date-Time fields.

FILEDEF PATIENT DISK activity.txt
-RUN

-WRITE PATIENT John     Doe      615 887-0000 20080215 540 ACTIVE
-WRITE PATIENT Jane     Doe      615 641-0000 20080215 540 ACTIVE

FILEDEF MASTER DISK patient.mas
-RUN

-WRITE MASTER FILENAME=PATIENT, SUFFIX=FIX
-WRITE MASTER SEGNAME=PATIENT
-WRITE MASTER FIELDNAME=FIRST,      FORMAT=A8, ACTUAL=A8, $
-WRITE MASTER FIELDNAME=FILL1,      FORMAT=A1, ACTUAL=A1, $
-WRITE MASTER FIELDNAME=LAST,       FORMAT=A8, ACTUAL=A8, $
-WRITE MASTER FIELDNAME=FILL2,      FORMAT=A1, ACTUAL=A1, $
-WRITE MASTER FIELDNAME=HOMEAREA,   FORMAT=A3, ACTUAL=A3, $
-WRITE MASTER FIELDNAME=FILL2,      FORMAT=A1, ACTUAL=A1, $
-WRITE MASTER FIELDNAME=HOMEPHONE,  FORMAT=A8, ACTUAL=A8, $
-WRITE MASTER FIELDNAME=FILL2,      FORMAT=A1, ACTUAL=A1, $
-WRITE MASTER FIELDNAME=DATE,       FORMAT=A8YYMD, ACTUAL=A8, $
-WRITE MASTER FIELDNAME=FILL2,      FORMAT=A1, ACTUAL=A1, $
-WRITE MASTER FIELDNAME=FROMM,      FORMAT=I3, ACTUAL=A3, $
-WRITE MASTER FIELDNAME=FILL2,      FORMAT=A1, ACTUAL=A1, $
-WRITE MASTER FIELDNAME=STATUS,     FORMAT=A6, ACTUAL=A6, $
-RUN

DEFINE FILE PATIENT
CURR_DATE/HYYMD = HINPUT(14, '&YYMD.000000', 8, 'HYYMDS');
FROM_TIME/HHIS = IF FROMM GE 0 THEN HADD(CURR_DATE, 'SECOND', FROMM, 8, 'HYYMDS') ELSE CURR_DATE;
END
-RUN
TABLE FILE PATIENT
PRINT
FIRST
LAST
HOMEAREA
HOMEPHONE
DATE
FROMM
STATUS
FROM_TIME
END
-RUN


I had to rename the field FROM to FROMM - I was getting an error, it appears FROM is a reserved word.

CURR_DATE is a date-time field with the current date - this is used temporarily. The value evaluates to today's date with 0 hours minutes seconds - 2008/02/13 00:00:00.

FROM_TIME is date-time field in Hours:Minutes:Seconds format. FROMM is added to CURR_DATE to determine the time that FROMM represents. It is assumed the FROMM is the number of seconds, though I have not seen this confirmed by you. If it's minutes, then simply change SECONDS to MINUTES. This is the field you are interested in.


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
I forgot to mention that the -WRITE statements are setting up the data and Master of your PATIENT file.

Also, you can change the format HHIS to HHISa to get am/pm displayed.


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
quote:
NUMSEC/I4 WITH PATIENT = '';

Maybe it helps if you equate the field NUMSEC to something that actually has a value. With the code above, the value of the field will always be 0.


GamP

- Using AS 8.2.01 on Windows 10 - IE11.
in Focus since 1988
LOgle,

Seems to me that your time field is not a time field, but an interger representing the number of minutes not seconds. If your time field is NUMMIN and contains 780, to convert this to "01:00 pm", do the following:
HOURS/I2=NUMMIN/60;
MINUTES/I2=NUMMIN-(HOURS*60);
AMPM/A3=IF HOURS GE 12 THEN ' pm' ELSE ' am';
DHOURS/I2=IF HOURS GE 12 THEN HOURS-12 ELSE HOURS;
DTIME/A8=EDIT(DHOURS) | ':' | EDIT(MINUTES) | AMPM;

Your input shows a FROM 540, which also seems to be minutes. This would convert to 9:00 am.

Actually, you could make this a function using the DEFINE FUNCTION if you needed to do this a lot.


In FOCUS since 1985. Prod WF 8.0.08 (z90/Suse Linux) DB (Oracle 11g), Self Serv, Report Caster, WebServer Intel/Linux.
Jgelona
It Works Now! Thank you sooo very much! I did this:

Define file Patient

DTIME/A8=EDIT(DHOURS) | ':' | EDIT(MINUTES) | AMPM;

END

TABLE FILE PATIENT
PRINT
'PATIENT.PATIENT.FIRST'
'PATIENT.PATIENT.LAST'
'PATIENT.PATIENT.HOMEAREA'
'PATIENT.PATIENT.HOMEPHONE'
'APPOINT.APPOINT.DATE'
'DTIME'
'PATIENT.PATIENT.STATUS'


V. 762
Windows XP
Have a question, i'm trying to convert minutes into HH:MM:SS as well and i'm using this logic and i have found that when i set the variable NUMSEC as the original poster shows this all works however when i try to use a value from another variable which i processed earlier in the report it doesnt????

Code i'm referring to:
NUMSEC/I4 = 164;
HHMMSS/I4= INT( IMOD(NUMSEC,3600,'I4')/60 ) * 100 +IMOD(NUMSEC,60,'I2');
TIME/A8=EDIT(HHMMSS,'99:99');

output 02:44 which is what i'm looking for (without pm/am)

My Example (becuase the minutes could be dynamic....)
REPORT_MINUTES/I6 = MINS;
HHMMSS/I4= INT( IMOD(REPORT_MINUTES,3600,'I4')/60 ) * 100 +IMOD(REPORT_MINUTES,60,'I2');
TIME/A8=EDIT(HHMMSS,'99:99');

output 00:00

the value that is in report_minutes is 164, now if i manually type 164 into NUMSEC or REPORT_MINUTES it all works? is there some internal conversion going on here? i'm displaying the value of what is in report_minutes and it is indeed 164...?


WebFocus 8.02, SQL Server 2008r2
What's the format of your MINS field?
Maybe you meant it to be &MINS - thereby making it a DM variable?


GamP

- Using AS 8.2.01 on Windows 10 - IE11.
in Focus since 1988
quote:
our MINS fiel

hi GamP,

I have tried both integer and decimal and no luck, here is the code before i use that field:

PER/D8.2= (CNT_RECORD_AMOUNT * .9) + .5;
PER_RECORD/I8=90_PER;
PER_VALUE/I5 =IF RECORD_NUMBER EQ PER_RECORD THEN PAT_MINS ELSE 0;

-* this is where i have tried both integer and decemial
REPORT_MINUTES/D8.2 = PER_VALUE/60;

REPORT_MINUTES/I6 = MINS;
HHMMSS/I4= INT( IMOD(REPORT_MINUTES,3600,'I4')/60 ) * 100 +IMOD(REPORT_MINUTES,60,'I2');
TIME/A8=EDIT(HHMMSS,'99:99');


WebFocus 8.02, SQL Server 2008r2
This seems to work for me, the correct time in minutes and seconds is calculated:

TABLE FILE CAR
PRINT
COMPUTE REPORT_MINUTES/I6 = WEIGHT;
COMPUTE HHMMSS/I4 = 
  INT( IMOD(REPORT_MINUTES,3600,'I4') / 60 ) * 100 + 
  IMOD(REPORT_MINUTES,60,'I2');
COMPUTE TIME/A5 = EDIT(HHMMSS,'99:99');
END



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
If you need it as a time value so that you can sort it:
TABLE FILE CAR
PRINT 
 WEIGHT AS 'Seconds'
 COMPUTE T1/HHISa MISSING ON = HADD(DT(0), 'ss', WEIGHT, 8, T1);  AS 'Seconds as Time'
 LENGTH AS 'Minutes'
 COMPUTE T2/HHIa MISSING ON = HADD(DT(0), 'mi', LENGTH, 8, T2);  AS 'Minutes as Time'
END

Keep in mind what will happen if your times hit 24 hours or more.


WebFOCUS 7.6.7
Linux
HTML, Excel, PDF