Focal Point Banner


As of December 1, 2020, Focal Point is retired and repurposed as a reference repository. We value the wealth of knowledge that's been shared here over the years. You'll continue to have access to this treasure trove of knowledge, for search purposes only.

Join the TIBCO Community
TIBCO Community is a collaborative space for users to share knowledge and support one another in making the best use of TIBCO products and services. There are several TIBCO WebFOCUS resources in the community.

  • From the Home page, select Predict: WebFOCUS to view articles, questions, and trending articles.
  • Select Products from the top navigation bar, scroll, and then select the TIBCO WebFOCUS product page to view product overview, articles, and discussions.
  • Request access to the private WebFOCUS User Group (login required) to network with fellow members.

Former myibi community members should have received an email on 8/3/22 to activate their user accounts to join the community. Check your Spam folder for the email. Please get in touch with us at community@tibco.com for further assistance. Reference the community FAQ to learn more about the community.


Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     Converting time to second

Read-Only Read-Only Topic
Go
Search
Notify
Tools
Converting time to second
 Login/Join
 
Silver Member
posted
Hi,
I tried to determine the number of hours to add to a time variable in HH.MM.SS format, I then add the number of hours to the time variable. I use this 'total' time variable to determine whether the job should proceed or goes throught the loop. My code is as below.

-**********
-STARTTIME
-**********
-*
-SET &SLEEP = DECODE &&A_CODE ('04' 1, '09' 3600, '12' 7200, '08' 10800, ELSE 14400);
-*convert the time variable (&A_LOCKTM) to second
-SET LOCKTM/D6 = HTIME(8, &A_LOCKTM, LOCKTM);
-*add them together
-SET &AGENTST = LOCKTM + &SLEEP;
-*
-SET &STARTTM/HYYMDm = &DATEDMYY || &AGENTST;
-*get the current date and time
-SET &CURDT = HGETC(8, 'HYYMDm);
-*
-IF &CURDT GE &STARTTM GOTO ENDPROC;
-*
!sleep &STARTTM
-RUN
-GOTO ENDPROC

It is not working. Any suggestion is much appreciated.

Thanks


WebFOCUS 5.2 upgrading to the latest version at the moment.
UNIX
HTML
 
Posts: 35 | Registered: September 16, 2009Report This Post
Expert
posted Hide Post
First thing is the use of formats on the amper variables. Amper variables only have alpha or number, and number depends on the DMPRECISION setting.

What is the format of &A_LOCKTM ?

I think you can do this , but with a bit of a rework of the functions used.

Its been mentioned many times in the forum and the documentation that the datetime functions do not lend them selves to dialog manager calculations, you have to be very careful whet you create and store in a varable.


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!

 
Posts: 6347 | Location: 33°49'23.0"S, 151°11'41.0"E | Registered: October 31, 2006Report This Post
Virtuoso
posted Hide Post
Sophie,

quote:
-SET &SLEEP = DECODE &&A_CODE ('04' 1, '09' 3600, '12' 7200, '08' 10800, ELSE 14400);
-*convert the time variable (&A_LOCKTM) to second
-SET LOCKTM/D6 = HTIME(8, &A_LOCKTM, LOCKTM);
-*add them together
-SET &AGENTST = LOCKTM + &SLEEP;
-*
-SET &STARTTM/HYYMDm = &DATEDMYY || &AGENTST;
-*get the current date and time
-SET &CURDT = HGETC(8, 'HYYMDm);
-*
-IF &CURDT GE &STARTTM GOTO ENDPROC;
-*
!sleep &STARTTM
-RUN
-GOTO ENDPROC

I'm afraid you are mixing up Dialog Manager code with DEFINE code.
For example:
-SET LOCKTM/D6 = HTIME(8, &A_LOCKTM, LOCKTM);  

-SET must have a &variable after. The &variable does not have a format.
Then &A_LOCKTM being an &variable probably does not contain a datetime value but an alpha.
So, could you please tell what are the contents of your variables?


Daniel
In Focus since 1982
wf 8.202M/Win10/IIS/SSA - WrapApp Front End for WF

 
Posts: 1980 | Location: Tel Aviv, Israel | Registered: March 23, 2006Report This Post
Silver Member
posted Hide Post
Thank you for your response.

The format for &A_LOCKTM = HHMMSS('A8')

The problem is that I tried to add the number of hours (which is currently decoded in 'second' for the &SLEEP variable) to the &A_LOCKTM variable (with format HH.MM.SS) and I am not sure what is the best way to do this?

Thanks


WebFOCUS 5.2 upgrading to the latest version at the moment.
UNIX
HTML
 
Posts: 35 | Registered: September 16, 2009Report This Post
Expert
posted Hide Post
I think you should be using the datetime functions.

e.g.
-SET &TIM = HCNVRT(HGETC(8, 'HYYMDs'), '(HYYMDs)', 23, 'A23') ;


This gets the current date and time as text.

You can use HADD to add to this, but you need to convert back to a date time value before the add, and convert back to text after.


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!

 
Posts: 6347 | Location: 33°49'23.0"S, 151°11'41.0"E | Registered: October 31, 2006Report This Post
Virtuoso
posted Hide Post
Sophie,

Let's take this backward:
You want to run the "sleep" program with a value which is the date and time until when to sleep.
What is supposed to be the format of this parameter? A date followed by a time? Spaces in between? Slashes? Colons? Or is it in binary?
Once you know this, then you can go about putting it together.


Daniel
In Focus since 1982
wf 8.202M/Win10/IIS/SSA - WrapApp Front End for WF

 
Posts: 1980 | Location: Tel Aviv, Israel | Registered: March 23, 2006Report This Post
Silver Member
posted Hide Post
The job is to go to 'sleep' if the 'time calculated' variable is GE to the current time.
The format for the 'time calculated' is DDMMYYY HH:MM:SS so that it can compare with the current date and time.

I have changed my code as below. My question is how do I convert the &SLEEP in 'second' format to 'hour'?

-SET &SLEEP = DECODE &&VWA_A_CODE ('04' 1, '09' 3600, '12' 7200, '08' 10800, ELSE 14400);
-*
-*convert the second to hours
-SET &LOCKTM = (&SLEEP*60)*60;
-*
-*Add hours to the &A_LOCKTM (which is in HH.MM.SS format)
-SET &AGENTST = HADD(&A_LOCKTM, 'HOUR', &LOCKTM, 8, &AGENTST);
-*
-*Get the date and time to start &STARTTM (format DD/MM/YYYY HH:MM:SS)
-SET &STARTTM = &DATEDMYY || &AGENTST;
-*
-*Get the current date and time
-SET &CURDT = HGETC(8, 'HYYMDm');
-*
-IF &CURDT GE &STARTTM GOTO ENDPROC;
-*
!sleep &STARTTM
-RUN
-GOTO ENDPROC

Thanks


WebFOCUS 5.2 upgrading to the latest version at the moment.
UNIX
HTML
 
Posts: 35 | Registered: September 16, 2009Report This Post
Silver Member
posted Hide Post
Oop! to convert the second to hours would be division rather than multiply.

I know that it is incorrected syntax. Just want to show what I am trying to do.

Can I use the HINPUT function to convert this? Otherwise, what is the best way to do this?

Thanks


WebFOCUS 5.2 upgrading to the latest version at the moment.
UNIX
HTML
 
Posts: 35 | Registered: September 16, 2009Report This Post
Virtuoso
posted Hide Post
Well, I tried using the functions.
In the end, a bit of Dialog Manager does the trick. But maybe you can do better:
 
-SET &ECHO=ALL;
-* File sophie01.fex
-DEFAULT &&VWA_A_CODE='09', &A_LOCTM='12:05:25'
-SET &SLEEP = DECODE &&VWA_A_CODE ('04' 1, '09' 3600, '12' 7200, '08' 10800, ELSE 14400);
-*
-*Extract time components 
-SET &HH_LOCTM=EDIT(&A_LOCTM, '99');
-SET &MM_LOCTM=EDIT(&A_LOCTM, '$$$99');
-SET &SS_LOCTM=EDIT(&A_LOCTM, '$$$$$$99');
-*Convert time to seconds
-SET &SEC_LOCTM=&HH_LOCTM * 3600 + &MM_LOCTM * 60 + &SS_LOCTM;
-TYPE &SEC_LOCTM
-*Add &SLEEP
-SET &SEC_WAKETM=&SEC_LOCTM + &SLEEP;
-TYPE &SEC_WAKETM
-*Convert &SEC_WAKETM to format HH:MM:SS
-* Check if new day. If so calculate number of days to add
-SET &ADD_DAY=IF &SEC_WAKETM GT 86400 THEN &SEC_WAKETM / 86400 ELSE 0;
-*Retrieve number of seconds for Wake time
-SET &SEC_WAKETM=IMOD(&SEC_WAKETM, 86400, 'I6');
-* Extract time components; check if less than 10 to add leading 0
-SET &HH=&SEC_WAKETM / 3600;
-SET &HH=IF &HH LT 10 THEN '0' | &HH ELSE &HH;
-SET &MM=(&SEC_WAKETM - &HH * 3600) / 60;
-SET &MM=IF &MM LT 10 THEN '0' | &MM ELSE &MM;
-SET &SS=IMOD(&SEC_WAKETM, 60, 'I2');
-SET &SS=IF &SS LT 10 THEN '0' | &SS ELSE &SS;
-* Add days to today
-SET &WNDATE=AYMD(&YYMD, &ADD_DAY, 'I8YYMD');
-*Convert to DMYY
-SET &WDATE=CHGDAT('YYMD', 'DMYY', &WNDATE, 'A10');
-TYPE &WDATE 
-*Get the date and time to start &STARTTM (format DD/MM/YYYY HH:MM:SS)
-SET &STARTTM = EDIT(&WDATE, '99/99/9999 ') | &HH | ':' | &MM | ':' | &SS;
-TYPE &STARTTM
-*
-*Get the current date and time
-SET &CURDT = &DATEDMYY | ' ' | STRREP(8, &TOD, 1, '.', 1, ':', 8, 'A8');
-*
-IF &CURDT GE &STARTTM GOTO ENDPROC; 
-EXIT
-*
!sleep &STARTTM
-RUN
-GOTO ENDPROC
-ENDPROC


Daniel
In Focus since 1982
wf 8.202M/Win10/IIS/SSA - WrapApp Front End for WF

 
Posts: 1980 | Location: Tel Aviv, Israel | Registered: March 23, 2006Report This Post
Master
posted Hide Post
I think I would create a DEFINE FUNCTION for this. There is a good article on the IBI website:

Simplifying the use of Date Function in Dialogue Manager

There are also discussions here on Focal Point:

Yesterday's Date and same date last year

and

Get Last Business Day

I see no reason why one cannot do something similar with the DATETIME functions.


In FOCUS since 1985. Prod WF 8.0.08 (z90/Suse Linux) DB (Oracle 11g), Self Serv, Report Caster, WebServer Intel/Linux.
 
Posts: 975 | Location: Oklahoma City | Registered: October 27, 2006Report This Post
Silver Member
posted Hide Post
Thanks for the suggestion.

I have tried to run your suggestion and it prompted me the following message.

Task error:ibi.jlink.EdaPcb: Pcb2.: ibi.ngxxj.NGException: local error

It doesn't seem to relate to any syntax error. I did some research on this error message but could not find any information from internet. Do you know what cause this? Thanks


WebFOCUS 5.2 upgrading to the latest version at the moment.
UNIX
HTML
 
Posts: 35 | Registered: September 16, 2009Report This Post
Silver Member
posted Hide Post
Hi Danny,

I am still trying to resolve the error message shown. Just want to understand the reasons for the code below? Thanks

-* Extract time components; check if less than 10 to add leading 0
-SET &HH=&SEC_WAKETM / 3600;
-SET &HH=IF &HH LT 10 THEN '0' | &HH ELSE &HH;
-SET &MM=(&SEC_WAKETM - &HH * 3600) / 60;
-SET &MM=IF &MM LT 10 THEN '0' | &MM ELSE &MM;
-SET &SS=IMOD(&SEC_WAKETM, 60, 'I2');
-SET &SS=IF &SS LT 10 THEN '0' | &SS ELSE &SS;


WebFOCUS 5.2 upgrading to the latest version at the moment.
UNIX
HTML
 
Posts: 35 | Registered: September 16, 2009Report This Post
Virtuoso
posted Hide Post
Hi Sophie,

See some comments within the code:
-*extract hours from seconds (there are 3600 sec/hr)  
-SET &HH=&SEC_WAKETM / 3600;

-*prefix a 0 if the hour is only 1 digit
-SET &HH=IF &HH LT 10 THEN '0' | &HH ELSE &HH;

-*calculate number of minutes: seconds less number of hours * 3600 divided by 60
-SET &MM=(&SEC_WAKETM - &HH * 3600) / 60;

-*prfix a 0 if minutes has only 1 digit
-SET &MM=IF &MM LT 10 THEN '0' | &MM ELSE &MM;

-*calculate number of seconds: remainder of all seconds divided by 60
-SET &SS=IMOD(&SEC_WAKETM, 60, 'I2');

-*prefix a 0 if seconds has only 1 digit
-SET &SS=IF &SS LT 10 THEN '0' | &SS ELSE &SS;


I hope this makes it clearer.


Daniel
In Focus since 1982
wf 8.202M/Win10/IIS/SSA - WrapApp Front End for WF

 
Posts: 1980 | Location: Tel Aviv, Israel | Registered: March 23, 2006Report This Post
Virtuoso
posted Hide Post
I believe the Unix SLEEP command takes seconds as the default parameter and stops current processing for the specified number of seconds starting from the current date-time. So couldn't you simply SLEEP your process based on the number of seconds from your DECODE?

-SET &SLEEP = DECODE &&VWA_A_CODE ('04' 1, '09' 3600, '12' 7200, '08' 10800, ELSE 14400);
-*
! sleep &SLEEP
-RUN

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


WebFOCUS 7.7.05
 
Posts: 1213 | Location: Seattle, Washington - USA | Registered: October 22, 2007Report This Post
Silver Member
posted Hide Post
Thanks for the explanation.

Yes Dan, however, this will force the job to wait according to the seconds set regardless of when it is being executed.

The reason for the wait is for the dependency job to complete before it can start. For example, if the dependency job is finished on Sunday at 10am and the job is set to wait for 3600 sec, it should be started any time after Sunday 11am. Therefore, if the job is executed on Monday, it should start straight away without having to wait, etc.

Hope this explain why we need to do all these time calculation.

At the moment, when I incoporated Danny's suggested code, I get the error message below:

Task error:ibi.jlink.EdaPcb: Pcb2.: ibi.ngxxj.NGException: local error

Any suggestion of what cause this error would be very much appreciated.

Thanks


WebFOCUS 5.2 upgrading to the latest version at the moment.
UNIX
HTML
 
Posts: 35 | Registered: September 16, 2009Report This Post
Silver Member
posted Hide Post
Hi,
I am getting there to resolve the error message by doing 'process elimination'.

I am trying to convert a date with the format dd/mm/yyyy to I8yymd. I have tried the following functions CHGDAT, EDIT, DATECVT and HINPUT and I couldn't get it working.

What is the best way to convert this?
Thanks


WebFOCUS 5.2 upgrading to the latest version at the moment.
UNIX
HTML
 
Posts: 35 | Registered: September 16, 2009Report This Post
Expert
posted Hide Post
In a define or dialogue manager?

-* Set-up a date to mimic Sophie's requirement
-SET &S_Date = EDIT(&DMYY,'99/99/9999');

-* Now manipulate it in dialogue manager
-SET &I8YYMD = DATECVT(EDIT(&S_Date,'99$99$9999'), 'A8DMYY', 'I8YYMD');

-* Now in a define
DEFINE FILE CAR
  X_DATE/A8     WITH COUNTRY = &DMYY.QUOTEDSTRING;
  S_DATE/A10    WITH COUNTRY = EDIT(X_DATE,'99/99/9999');
  I_DATE/I8YYMD WITH COUNTRY = DATECVT(EDIT(S_DATE,'99$99$9999'), 'A8DMYY', 'I8YYMD');
END
TABLE FILE CAR
  SUM S_DATE
      I_DATE
   BY HIGHEST 1 COUNTRY NOPRINT
END


T

This message has been edited. Last edited by: Tony A,



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 
 
Posts: 5694 | Location: United Kingdom | Registered: April 08, 2004Report This Post
Silver Member
posted Hide Post
quote:
-* Set-up a date to mimic Sophie's requirement
-SET &S_Date = EDIT(&DMYY,'99/99/9999');

-* Now manipulate it in dialogue manager
-SET &I8YYMD = DATECVT(EDIT(&S_Date,'99$99$9999'), 'A8DMYY', 'I8YYMD');


Thank you Tony. It works!

As I am new to programming, I understand that you use the EDIT function to convert the date from alphanumeric to numeric format before using DATECVT. Why do you need to use the EDIT function again within the DATECVT function?

Thanks


WebFOCUS 5.2 upgrading to the latest version at the moment.
UNIX
HTML
 
Posts: 35 | Registered: September 16, 2009Report This Post
Expert
posted Hide Post
Sophie,

Tony's asleep right now, so I'll answer.

The first -SET command is only to set up a variable with a value that has slashes in it - just like the one you need to convert. (The slash in this EDIT function call places the slash or any other character of your choice: the system variable &DMYY has no slashes, so, to replicate a variable like yours the EDIT function adds the slashes in the appropriate positions).

Tony could have used this instead (&DATEMDYY being a system variable not normally visible):

-SET &S_Date = &DATEMDYY;

The second -SET command is to remove the slashes (or whatever other separator character there is) - the $ is an EDIT mask to exclude a character.

"WebFOCUS 5.2" - I certainly hope your company upgrades soon!

Cheers,

This message has been edited. Last edited by: Francis Mariani,


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
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Report This Post
Silver Member
posted Hide Post
Thank you for the explanation.

Last question, I am trying to retrieve the current date and time in the following format dd/nn/yyyy hh:mm:ss with the following code.

-*Get the current date and time
-SET &CURT = STRREP(8,&TOD,1,'.',1,':',8,'A8');
-SET &CURDT = &DATEDMYY | ' ' | &CURT;

However, it doesn't like the way the STRREP function used above.

What is wrong with the STRREP used above?
Or if there is a better way to obtain the current date and time in the above format?

Many thanks


WebFOCUS 5.2 upgrading to the latest version at the moment.
UNIX
HTML
 
Posts: 35 | Registered: September 16, 2009Report This Post
Expert
posted Hide Post
-SET &S_DATE = &DATEDMYY;
-SET &S_TIME = EDIT(HHMMSS('A8'),'99$:99$:99');

-SET &S_DTTM = &S_DATE | ' ' | &S_TIME;

-TYPE &S_DATE
-TYPE &S_TIME
-TYPE &S_DTTM

(The "$" is to remove the ".", the ":" is to add the ":")

or

-SET &S_DTTM = &DATEDMYY | ' ' | EDIT(HHMMSS('A8'),'99$:99$:99');


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
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Report This Post
Silver Member
posted Hide Post
Thank you. Appreciated for the help and explanation.

It's working now Smiler


WebFOCUS 5.2 upgrading to the latest version at the moment.
UNIX
HTML
 
Posts: 35 | Registered: September 16, 2009Report This Post
Expert
posted Hide Post
quote:
Tony's asleep right now, so I'll answer.

Thanks for covering off Francis Smiler

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 
 
Posts: 5694 | Location: United Kingdom | Registered: April 08, 2004Report This Post
Expert
posted Hide Post
I thought I'd jump in as things were as slow as a badminton game...


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
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Report This Post
Master
posted Hide Post
I think you mean a Chinese or Indonesian badminton game ...


WebFOCUS 7.7.05 Windows, Linux, DB2, IBM Lotus Notes, Firebird, Lotus Symphony/OpenOffice. Outputs PDF, Excel 2007 (for OpenOffice integration), WP
 
Posts: 674 | Location: Guelph, Ontario, Canada ... In Focus since 1985 | Registered: September 28, 2010Report This Post
Silver Member
posted Hide Post
Hi again,

The last part of the code to compare between the 2 date (&CURDT and STARTTM) in date and time format doesn't seem to work correctly.

Can I compare 2 date in the date and time format?

If not, What is the best way to convert the current date and time to second? so that I can compare this with the &STARTTIM.

-IF &CURDT GE &STARTTM GOTO ENDPROC;
-*
!sleep &STARTTM
-RUN
-GOTO ENDPROC

Many thanks


WebFOCUS 5.2 upgrading to the latest version at the moment.
UNIX
HTML
 
Posts: 35 | Registered: September 16, 2009Report This Post
  Powered by Social Strata  

Read-Only Read-Only Topic

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     Converting time to second

Copyright © 1996-2020 Information Builders