Focal Point
[CLOSED] DATEDIF function with variables

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

September 12, 2009, 02:47 PM
Piscian
[CLOSED] DATEDIF function with variables
Hi All,

This might seem bit silly, but I am not able to get diff between dates.
Code is-
  
-SET &START_DATE = '2008/05/01';
-SET &END_DATE = '2008/07/31';
-SET &DATED = DATEDIF(&END_DATE, &START_DATE, 'D');
-TYPE &DATED


I get error-
(FOC36355) INVALID TYPE OF ARGUMENT #2 FOR USER FUNCTION DATEDIF

Please help.

Thanks!

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


Thanks and Regards,
Piscian

WebFocus 714
Windows Server 2003
Enterprise Edition
HTML,Excel,PDF
September 12, 2009, 09:23 PM
jimster06
My copy of (Almost ) 1001 Ways to Work with DATES in WebFOCUS contains the following passage about DATEDIF ..."It does not curently work with Dialogue Manager variables." p 289.
And I highly recommend the book.
Here is a definitive discussion.
edit to add URL

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


jimster06
DevStu WF 7.6.11
W7
HTML, PDF, EXL2K
September 13, 2009, 04:53 PM
j.gross
You can use DATEDIF in dialog manager -SET, with amper vars as the date arguments, provided you apply .QUOTEDSTRING to them:

Code:
-SET &DT1='2008/05/01';
-SET &DT2='2008/07/31';
-SET &DT3=DATEDIF( &DT1.QUOTEDSTRING, &DT2.QUOTEDSTRING, 'D');
-SET &DT4=DATEDIF( &DT1.QUOTEDSTRING, &DT2.QUOTEDSTRING, 'WD');
-SET &DT5=DATEDIF( &DT1.QUOTEDSTRING, &DT2.QUOTEDSTRING, 'M');

-? &DT


Result:
 CURRENTLY DEFINED & VARIABLES STARTING WITH 'DT':
 &DT1          = 2008/05/01
 &DT2          = 2008/07/31
 &DT3          = 91
 &DT4          = 65
 &DT5          = 2



- Jack Gross
WF through 8.1.05
September 14, 2009, 09:41 AM
GinnyJakes
You can also use AYMD if you take out the slashes.


Ginny
---------------------------------
Prod: WF 7.7.01 Dev: WF 7.6.9-11
Admin, MRE,self-service; adapters: Teradata, DB2, Oracle, SQL Server, Essbase, ESRI, FlexEnable, Google
September 14, 2009, 10:07 AM
Francis Mariani
Jack,

You seriously have a secret horde of great WebFOCUS tips that are stored outside the box!

I bet this is not documented anywhere - QUOTEDSTRING is only discussed for embedded single-quotes.

Thanks for the tip.


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
September 14, 2009, 10:45 AM
GamP
quote:
QUOTEDSTRING is only discussed for embedded single-quotes

Which is why you could also code it like:
-SET &DT1='2008/05/01';
-SET &DT2='2008/07/31';
-SET &DT3=DATEDIF( '&DT1.EVAL', '&DT2.EVAL', 'D');
-SET &DT4=DATEDIF( '&DT1.EVAL', '&DT2.EVAL', 'WD');
-SET &DT5=DATEDIF( '&DT1.EVAL', '&DT2.EVAL', 'M');
-? &DT

This will produce the same results.


GamP

- Using AS 8.2.01 on Windows 10 - IE11.
in Focus since 1988
September 14, 2009, 11:21 AM
Darin Lee
Interesting Jack. I'll have to try that one. Another way to get this to work is to use the DATECVT function first (like DATECVT(&YYMD,'I8YYMD','YYMD') and then use DATEDIF on those converted dates. Works for DATEADD as well which also "cannot be used with Dialogue Manager."

-SET &AUTO_DATE=DATECVT(DATEADD(DATECVT(&YYMD,'I8YYMD','YYMD'), 'D', -7),'YYMD','A8YYMD');


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
September 14, 2009, 11:31 AM
Francis Mariani
I've always used the DATECVT method, but this is so much more elegant:
-SET &DT6A = DATEADD(&YYMD.QUOTEDSTRING, 'D', -7);
And, as GamP points out,
-SET &DT6B = DATEADD('&YYMD.EVAL', 'D', -7);
works as well. Why didn't I think of that? No need for the DATECVT function in DM any more.


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
September 14, 2009, 05:59 PM
j.gross
FM --

Not so fast. (Try those with +61 instead of -7 Wink )

The input is required to represent a "smart" date (accepted in either offset integer form or formatted date form), and the output is an offset integer. &YYMD, even with the quotes, is interpreted as an offset of +yy,yym,mdd.

Bottom line -- use a formatted value (&DATEYYMD rather than &YYMD), and apply DATECVT to the result to obtains a displayable date.


- Jack Gross
WF through 8.1.05
September 29, 2009, 09:59 AM
Francis Mariani
Yikes! Just found this update after seeing Tony's posting about DATEMOV, I'll be sticking with the DATECVT option, thank you.


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