Focal Point
[CLOSED] hOW CAN WE GET THE CURRENT TIME?

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

June 26, 2007, 05:56 PM
Usernani
[CLOSED] hOW CAN WE GET THE CURRENT TIME?
As we get the current date by &YYMD is there way to get or compare the time with current time ?
Thanks for your help

This message has been edited. Last edited by: Kerry,
June 26, 2007, 09:49 PM
susannah
&TOD




In Focus since 1979///7706m/5 ;wintel 2008/64;OAM security; Oracle db, ///MRE/BID
June 27, 2007, 04:40 AM
OPALTOSH
Unfortunately &TOD is static. It is set at the beginning of the current process and does not change. If you wnat the actual time at various stages during your process use the HHMMSS function as it returns the system time at the instant.
June 27, 2007, 09:59 AM
Usernani
thanks, what I actually need is if current time is let's say GE 06:00:00 and LE 08:00:00 then run the program, else do not run the program.
With current date it works as I can use &YYMD but what should I use for current time?
Thanks for your help
June 27, 2007, 10:00 AM
BobSh
To ensure you get the current date and time you would want to do the following either in your focexec or in edasprof.prf:
SET DATETIME=CURRENT


WebFOCUS 7.7.05M, gen 144, Windows 2008 Server R2 64-bit, Tomcat 6.0.33, IIS 7.0, SQL Server, Excel 2013, PDF, HTML, FOCUS files.
June 27, 2007, 10:01 AM
ira
try the following:
-SET &TIME = HHMMSS('A8');

OR

-SET &TIME = HHMMSS(TIME);


aix-533,websphere 5.1.1,apache-2.0,
wf 538(d), 537 (p),
==============
7.6.11 (t) aix 5312
websphere 6.1.19
apache 2.0
June 27, 2007, 11:23 AM
ira
HOW IS THIS?

-BEGINN
-SET &STARTTIME = '06:00:00';
-SET &ENDTIME = '08:00:00';
-SET &TIME = HHMMSS('A8');
-IF ((&TIME GE &STARTTIME ) AND (&TIME LE &ENDTIME ))GOTO INTIME;
-LBL0
-NOTINTIME
-TYPE SORRY YA MISSED THE TIME ZONE
-GOTO XIT
-INTIME
-TYPE OK YOU MADE IT ON TIME
-XIT


aix-533,websphere 5.1.1,apache-2.0,
wf 538(d), 537 (p),
==============
7.6.11 (t) aix 5312
websphere 6.1.19
apache 2.0
June 27, 2007, 12:11 PM
Usernani
Thanks, this is great, but I still have an issue. it seems that it does not care for the minutes. In the example that you gave me I thought it should display 'SORRY YA MISSED THE TIME ZONE' if the current time is 8:10 but it displays 'OK YOU MADE IT ON TIME' . It seems it is only conparing the hours and not minutes or seconds. Any suggestions???
Thank you very much

BEGINN
-SET &STARTTIME = '06:00:00';
-SET &ENDTIME = '08:00:00';
-SET &TIME = HHMMSS('A8');
-IF ((&TIME GE &STARTTIME ) AND (&TIME LE &ENDTIME ))GOTO INTIME;
-LBL0
-NOTINTIME
-TYPE SORRY YA MISSED THE TIME ZONE
-GOTO XIT
-INTIME
-TYPE OK YOU MADE IT ON TIME
-XIT
June 27, 2007, 12:27 PM
ira
my mistake. i had ':' in the startdate and enddate. I should have used '.' see below...

-SET &ECHO = 'ALL';
-SET &STARTTIME = '06.00.00';
-SET &ENDTIME = '12.29.00';
-SET &TIME = HHMMSS('A8');
-TYPE &TIME
-IF ((&TIME GE &STARTTIME ) AND (&TIME LE &ENDTIME ))GOTO INTIME;
-NOTINTIME
-TYPE SORRY YA MISSED THE TIME ZONE
-GOTO XIT
-INTIME
-TYPE OK YOU MADE IT ON TIME
-XIT


aix-533,websphere 5.1.1,apache-2.0,
wf 538(d), 537 (p),
==============
7.6.11 (t) aix 5312
websphere 6.1.19
apache 2.0
June 27, 2007, 12:34 PM
Francis Mariani
That may be because the HHMMSS function returns . not : between the hours, minutes and seconds. Your &STARTTIME and &TIME has different separators.

Try this:

-SET &ECHO=ALL;
-BEGINN
-SET &STARTTIME = '12:00:00';
-SET &ENDTIME = '14:00:00';
-SET &TIME = EDIT(HHMMSS('A8'),'99$:99$:99');
-IF ((&TIME GE &STARTTIME ) AND (&TIME LE &ENDTIME ))GOTO INTIME;
-LBL0
-NOTINTIME
-TYPE SORRY YA MISSED THE TIME ZONE
-GOTO XIT
-INTIME
-TYPE OK YOU MADE IT ON TIME
-XIT

I'm not sure if the time returned with the HHMMSS function is always in 24 hour format.


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
June 27, 2007, 01:01 PM
ira
True I could have altered to test it with ':' but quicker to go with their format and no need to add extra edit in. Glad it worked 4ya. Happy to help.

Ira


aix-533,websphere 5.1.1,apache-2.0,
wf 538(d), 537 (p),
==============
7.6.11 (t) aix 5312
websphere 6.1.19
apache 2.0
June 27, 2007, 01:03 PM
ira
o yeh and forgot to mention it goes to 23:59:59


aix-533,websphere 5.1.1,apache-2.0,
wf 538(d), 537 (p),
==============
7.6.11 (t) aix 5312
websphere 6.1.19
apache 2.0
June 27, 2007, 02:05 PM
Usernani
THANK YOU VERY MUCH. I just used '.' instead of ':' as Ira suggested and its working great.
Once again thank you very much
June 28, 2007, 01:52 PM
FrankDutch
What is current time.....
on my watch it is now 19:53:30 (I live in Europe)

but when I hit the enter it is a bit later and I now my watch is a few minutes before, so I will not mis my daily train....

LOL




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

September 13, 2010, 09:45 AM
Ted Michalski
I need this exact format:

9/13/2010 9:50 AM

Can you give me the format? HHMMSS displays the seconds and I don't want that.


7.7.02
Windows
EXCEL, PDF, CSV, TEXT
September 13, 2010, 09:51 AM
susannah
&TOD




In Focus since 1979///7706m/5 ;wintel 2008/64;OAM security; Oracle db, ///MRE/BID
September 13, 2010, 10:00 AM
GamP
Something like this perhaps?
-SET &NOW = EDIT(HCNVRT(HGETC(8,'HMDYYm'),'(HMDYYSA)',30,'A30'),'9999999999999999$$$ 99');
-TYPE &NOW

Hope this helps ...


GamP

- Using AS 8.2.01 on Windows 7 - IE11.
in Focus since 1988
September 13, 2010, 10:35 AM
ira
I prefer GamP solution; however, if you want something a little more broken up: try this

-SET &TIME = HHMMSS('A8'); 
-SET &AM_PM = IF (EDIT(&TIME ,'99') GE '13') THEN 'PM' ELSE 'AM';
-SET &TIME2 = &DATE ||(' '|EDIT(&TIME ,'99:'))||EDIT(&TIME ,'$$$99')||(' '|&AM_PM );
-TYPE &TIME2 



aix-533,websphere 5.1.1,apache-2.0,
wf 538(d), 537 (p),
==============
7.6.11 (t) aix 5312
websphere 6.1.19
apache 2.0
September 13, 2010, 11:53 AM
Glenda
Do you need it as a variable or are you setting a display field?

If you are setting a display field then you can use:


DEFINE FILE CAR
DATETIME/HMDYYIA = HGETC(10, 'HMDYYIA');
END
TABLE FILE CAR
PRINT
	  DATETIME
      MODEL NOPRINT
WHERE RECORDLIMIT EQ 1
END
-EXIT



Glenda

In FOCUS Since 1990
Production 8.2 Windows
September 14, 2010, 12:29 PM
Ted Michalski
Thanks GamP. works great.


7.7.02
Windows
EXCEL, PDF, CSV, TEXT
September 16, 2010, 09:02 PM
Doug
Seeing that it's a function, it really doesn't matter what is within the parenthesis. I always used &TOD, just as a reference to TOD. But, even though the documentation (which is geared towards DEFINE and COMPUTE) states that it should be the OUTFIELD, anything works there. I, imho, don't see wasting the DEFINE or COMPUTE (on every row) for a semi-constant value. Use DM and the associated variable. Besides, using a "AND COMPUTE NOWTIME/A8 = HHMMSS(NOWTIME); NOPRINT" (as per F1 HELP) may cause different times to be displayed in the heading (on a very large report or when executed on a very slow system (I've seen this. Really, I did).

This was just for the fun of it,
Doug
September 16, 2010, 09:04 PM
Doug
But, while I'm here talking (ok, typeing) about TIME functions. Does anyone have a TIMEDIF which is kind of like the DATEDIF, only with TIME? Great for time stamping...
September 16, 2010, 10:09 PM
susannah
yes, its for dialog manager.
it measures the elapsed time of a job
from start to finish and calculates the duration,
you want it Doug?




In Focus since 1979///7706m/5 ;wintel 2008/64;OAM security; Oracle db, ///MRE/BID
September 16, 2010, 10:31 PM
Doug
Thanks for offering Susannah, I Sure Do... PM or Post...
September 17, 2010, 10:04 AM
ira
Doug, try this. Ira

  DEFINE FUNCTION TIMEDIFF(STRT_TIME/A8,END_TIME/A8)
-*SPLIT OUT HH MM SS; CONVERT TO 'I' FOR STRT_TIME AND END_TIME
STRT_HH/I2=EDIT(EDIT(STRT_TIME,'99'));
STRT_MM/I2=EDIT(EDIT(STRT_TIME,'$$$99'));
STRT_SS/I2=EDIT(EDIT(STRT_TIME,'$$$$$$99'));
STRT_SEC/I9=(STRT_HH * 3600)+(STRT_MM * 60) + STRT_SS ;
END_HH/I2=EDIT(EDIT(END_TIME,'99'));
END_MM/I2=EDIT(EDIT(END_TIME,'$$$99'));
END_SS/I2=EDIT(EDIT(END_TIME,'$$$$$$99'));
END_SEC/I9=(END_HH * 3600)+(END_MM * 60) + END_SS ;
DIFF_SCNDS/I9=END_SEC -STRT_SEC;
-*CONVERT BACK TO HH MM SS
HRS_DIFF/I2L=DIFF_SCNDS /3600;
MINS_DIFF/I2L = (DIFF_SCNDS - (HRS_DIFF * 3600))/60;
SECS_DIFF/I2L = (DIFF_SCNDS - (HRS_DIFF * 3600)) - (MINS_DIFF * 60);
-* FLLIP BACK TO ALPHA; ADD IN THE (COLONS) :'S
TIMEDIFF/A8=EDIT(HRS_DIFF) | ':' | EDIT(MINS_DIFF) | ':' | EDIT(SECS_DIFF);
END
-* using the car db...
DEFINE FILE CAR
STRT_TIME/A8 ='12:02:11';
END_TIME/A8  ='14:22:22';
END
TABLE FILE CAR
PRINT STRT_TIME AS 'Starting Time:'  END_TIME  AS 'Ending Time:'  
 
COMPUTE ELAPSED/A8= TIMEDIFF(STRT_TIME,END_TIME); AS 'Elapsed Time:'
      COUNTRY NOPRINT
IF RECORDLIMIT EQ 1
END



aix-533,websphere 5.1.1,apache-2.0,
wf 538(d), 537 (p),
==============
7.6.11 (t) aix 5312
websphere 6.1.19
apache 2.0
September 17, 2010, 09:06 PM
Doug
Thanks Ira, I'll keep note of this. However, I'm really looking for a DM version...
September 19, 2010, 05:42 PM
Dan Satchell
You could capture the date and time before and after your task and then use date-time functions to calculate the difference in seconds. I used a -REPEAT loop as my task here in order to get a meaningful time difference between start and finish.

Originally I used HDIFF to calculate the difference for DAY, HOUR, MINUTE, and SECOND, but discovered that if the start and finish times spanned the new minute mark (e.g., 13:06:57 to 13:07:03), HDIFF was returning 1 minute for the MINUTE difference instead of zero. So I decided to take the HDIFF total seconds and use Dialogue Manager to perform the remaining calculations.

-SET &START = &YYMD | EDIT(HHMMSS('A8'),'99$99$99');
-*
-SET &COUNTER = 0 ;
-REPEAT ENDREPEAT1 100000 TIMES
-SET &COUNTER = &COUNTER + 1 ;
-ENDREPEAT1
-*
-RUN
-SET &FINISH    = &YYMD | EDIT(HHMMSS('A8'),'99$99$99');
-SET &START_DT  = HINPUT(14,'&START.EVAL',8,'HYYMDS');
-SET &FINISH_DT = HINPUT(14,'&FINISH.EVAL',8,'HYYMDS');
-SET &TIMEDIF   = HDIFF(&FINISH_DT,&START_DT,'SECOND','D10.0');
-SET &DAYS      = INT(&TIMEDIF / 86400);
-SET &HOURS     = INT(&TIMEDIF / 3600) - (&DAYS * 24);
-SET &MINUTES   = INT(&TIMEDIF / 60) - (&HOURS * 60) - (&DAYS * 24 * 60);
-SET &SECONDS   = &TIMEDIF - (&MINUTES * 60) - (&HOURS * 60 * 60) - (&DAYS * 24 * 60 * 60);
-*
-TYPE Start=&START, End=&FINISH
-TYPE Elapsed Time = &DAYS days, &HOURS hours, &MINUTES minutes, &SECONDS seconds

This message has been edited. Last edited by: Dan Satchell,


WebFOCUS 7.7.05
June 11, 2015, 05:14 PM
Doug
OK, it's time to revisit this.
SET PAGE = NOLEAD
DEFINE FUNCTION TIMEDIFF(STRT_TIME/A8,END_TIME/A8)
-*SPLIT OUT HH MM SS; CONVERT TO 'I' FOR STRT_TIME AND END_TIME
STRT_HH/I2=EDIT(EDIT(STRT_TIME,'99'));
STRT_MM/I2=EDIT(EDIT(STRT_TIME,'$$$99'));
STRT_SS/I2=EDIT(EDIT(STRT_TIME,'$$$$$$99'));
STRT_SEC/I9=(STRT_HH * 3600)+(STRT_MM * 60) + STRT_SS ;
END_HH/I2=EDIT(EDIT(END_TIME,'99'));
END_MM/I2=EDIT(EDIT(END_TIME,'$$$99'));
END_SS/I2=EDIT(EDIT(END_TIME,'$$$$$$99'));
END_SEC/I9=(END_HH * 3600)+(END_MM * 60) + END_SS ;
DIFF_SCNDS/I9=END_SEC -STRT_SEC;
-*CONVERT BACK TO HH MM SS
HRS_DIFF/I2L=DIFF_SCNDS /3600;
MINS_DIFF/I2L = (DIFF_SCNDS - (HRS_DIFF * 3600))/60;
SECS_DIFF/I2L = (DIFF_SCNDS - (HRS_DIFF * 3600)) - (MINS_DIFF * 60);
-* FLLIP BACK TO ALPHA; ADD IN THE (COLONS) :'S
TIMEDIFF/A8=EDIT(HRS_DIFF) | ':' | EDIT(MINS_DIFF) | ':' | EDIT(SECS_DIFF);
END
DEFINE FILE CAR
STRT_TIME/A8 ='12:02:05';
END_TIME/A8  ='13:02:10';
END
TABLE FILE CAR
PRINT STRT_TIME AS 'Start Time'  END_TIME  AS 'End Time'
COMPUTE ELAPSED/A8= TIMEDIFF(STRT_TIME,END_TIME); AS 'Elapsed Time'
BY COUNTRY
ON TABLE SUBFOOT
"SUBFOOT: <STRT_TIME <END_TIME <ELAPSED"
ON TABLE SUBTOTAL AS 'SUBTOTAL:'
END

The above code (posted by IRA on Fri Sep 17 2010 10:04) produces this.
COUNTRY   Start Time End Time Elapsed Time
ENGLAND   12:02:05   13:02:10 01:00:05 
FRANCE    12:02:05   13:02:10 01:00:05 
ITALY     12:02:05   13:02:10 01:00:05 
JAPAN     12:02:05   13:02:10 01:00:05 
W GERMANY 12:02:05   13:02:10 01:00:05 
SUBTOTAL:       
SUBFOOT: 12:02:05 13:02:10 01:00:05

What I need is for the "ON TABLE SUBTOTAL AS 'SUBTOTAL:'" to display the subtotals of the times. 'Elapsed Time' is 05:00:25. Or to display the time totals aligned in a SUBFOOT.

Or, a NFR which calculates time differences directly from a field which is formatted as 'HYYMDS'. This function needs to provide a result which is available in the ON TABLE or ON FIELD SUBTOTAL lines.

Let me know you thoughts and/or solution. I'll open a NFR in the meantime. Perhaps even a CASE.

Thanks in advance, Doug

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


   In FOCUS Since 1983 ~ from FOCUS to WebFOCUS.
   Most recent: 8204 Gen 48 in Test and Production.