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     SOLVED: How to convert yyyy/mm/dd string value to date value in dialog manager?

Read-Only Read-Only Topic
Go
Search
Notify
Tools
SOLVED: How to convert yyyy/mm/dd string value to date value in dialog manager?
 Login/Join
 
Member
posted
I have a variable in dialog manager that contains date in the format of 'yyyy/mm/dd'. How can I convert it to a date value so that I can apply the DATEADD function to it? I have searched in the forum but I have only found examples that work when the date value is coming from TABLE FILE. I have not been able to find examples that work in dialog manager.

This message has been edited. Last edited by: JC Zhu,


WebFOCUS 7.7.3
Windows, All Outputs
 
Posts: 28 | Registered: January 19, 2012Report This Post
Virtuoso
posted Hide Post
It depends as to what you are trying to use DATEADD for. If you need to use Weekdays or Business days, then DATEADD is good:
-SET &INPUTDATE = '2013/05/03';
-SET &NEWDATE =  HCNVRT(HDTTM(DATEADD(HDATE(HINPUT(8,EDIT(&INPUTDATE,'9999$99$99'),8,'HYYMDS'),'YYMD'),'WD',5),8,'HYYMDS'), '(HYYMD)', 10, 'A10');
-*                                                                                                     ------
-TYPE &NEWDATE

WD - Weekday, 5 for increment by 5. BD for business days using SET BUSDAYS.

If you want to use just days, months or years, HADD will work:

-SET &NEWDATE =  HCNVRT(HADD(HINPUT(8,EDIT(&INPUTDATE,'9999$99$99'),8,'HYYMDS'),'dd',5,8,'HYYMDS'),'(HYYMD)',10,'A10');
-*                                                                              ------
-TYPE &NEWDATE

dd - days, 5 for increment by 5. Check documentation for other options.


Alan.
WF 7.705/8.007
 
Posts: 1451 | Location: Portugal | Registered: February 07, 2007Report This Post
Virtuoso
posted Hide Post
If you're just trying to add or subtract days from the initial date value, you can also strip out the slashes with EDIT and use the legacy function AYMD. With AYMD, conversion to a SmartDate value is not necessary.


WebFOCUS 7.7.05
 
Posts: 1213 | Location: Seattle, Washington - USA | Registered: October 22, 2007Report This Post
Member
posted Hide Post
What if the variable has a single digit month or day? For example, 2013/5/2. How can that be handled?


WebFOCUS 7.7.3
Windows, All Outputs
 
Posts: 28 | Registered: January 19, 2012Report This Post
Virtuoso
posted Hide Post
It's more difficult! Referring to previous post, the code becomes:
-SET &INPUTDATE = '2013/5/1';
-SET &YEAR = GETTOK(&INPUTDATE,&INPUTDATE.LENGTH,1,'/',4,'A4');
-SET &MONTH = GETTOK(&INPUTDATE,&INPUTDATE.LENGTH,2,'/',2,'A2');
-SET &DATE = GETTOK(&INPUTDATE,&INPUTDATE.LENGTH,3,'/',2,'A2');
-SET &NEWDATE =  HCNVRT(HDTTM(DATEADD(HDATE(HSETPT(HSETPT(HSETPT(HGETC(8,'HYYMDS'),'year',&YEAR,4,'HYYMDS'),'month',&MONTH,2,'HYYMDS'),'dd',&DATE,2,'HYYMDS'),'YYMD'),'WD',2),8,'HYYMDS'),'(HYYMD)',10,'A10');
-*                                                                                                                                                                    ------
-TYPE &NEWDATE

or
-SET &INPUTDATE = '2013/5/1';
-SET &YEAR = GETTOK(&INPUTDATE,&INPUTDATE.LENGTH,1,'/',4,'A4');
-SET &MONTH = GETTOK(&INPUTDATE,&INPUTDATE.LENGTH,2,'/',2,'A2');
-SET &DATE = GETTOK(&INPUTDATE,&INPUTDATE.LENGTH,3,'/',2,'A2');
-SET &NEWDATE =  HCNVRT(HADD(HSETPT(HSETPT(HSETPT(HGETC(8,'HYYMDS'),'year',&YEAR,4,'HYYMDS'),'month',&MONTH,2,'HYYMDS'),'dd',&DATE,2,'HYYMDS'),'dd',4,8,'HYYMDS'),'(HYYMD)',10,'A10');
-*                                                                                                                                              ------
-TYPE &NEWDATE


Alan.
WF 7.705/8.007
 
Posts: 1451 | Location: Portugal | Registered: February 07, 2007Report This Post
Member
posted Hide Post
It is important to note that Dialogue Manager interprets dates as alphanumeric or numeric, and the date functions such as DATEADD requires a standard date stored as an offset from the base date.
What this means is you have to convert the date string to a date offset using the function DATECVT.
Here is a sample:
  
-* Initial Date string
-SET &MYDATE = '2012/01/01';

-*Removing the '/' from the date
-SET &MYDATE = EDIT(&MYDATE, '9999$99$99');

-*Converting the date to an offset
-SET &MYDATE_OFFSET = DATECVT(&MYDATE, 'I8YYMD', 'YYMD');

-* Now you can use the &MYDATE_OFFSET with most of the date manipulation functions, such as DATEADD and DATEMOV


Release: DevStudio 7703
OS: Win7
Outputs: HTML, PDF, EXCEL

 
Posts: 8 | Registered: November 29, 2011Report This Post
Member
posted Hide Post
Thanks for the answers. I have just found that I can more easily achieved that with passing the variable to the DATEADD function directly without any conversion. I tried this initially but it didn't work. I got this to work by adding single quotes around the variable name when passing the value to the DATEADD function. With the single quotes, DATEADD seems to be able to automatically interpret it as a date.


-SET &INPUTDATE = '2013/5/2';
-SET &NEWDATE = HCNVRT(HDTTM(DATEADD('&INPUTDATE', 'D', -1),8,'HYYMDS'),'(HYYMD)',10,'A10');
-TYPE &NEWDATE


WebFOCUS 7.7.3
Windows, All Outputs
 
Posts: 28 | Registered: January 19, 2012Report This Post
Virtuoso
posted Hide Post
quote:
With the single quotes, DATEADD seems to be able to automatically interpret it as a date.


Not in my experience it won't, nor according to the documentation.


Alan.
WF 7.705/8.007
 
Posts: 1451 | Location: Portugal | Registered: February 07, 2007Report 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     SOLVED: How to convert yyyy/mm/dd string value to date value in dialog manager?

Copyright © 1996-2020 Information Builders