Focal Point
DATEDIF help

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

April 10, 2008, 02:32 PM
MarkWood
DATEDIF help
Hello, I was just doing a quick querry to an amper variable to type out the difference in days between two dates and I constently get a return of 0 Here is the code I am using to try and get what I am looking for:

-SET &DAYSAGO = DATEDIF(20050202, 20080410, 'D');
-TYPE The report was last run &DAYS_AGO days ago.

Every time I try this, I get a 0 in the &DAYS_AGO variable. I'm starting to rip my hair out.

Any suggestions would be wonderful.
April 10, 2008, 03:33 PM
smiths
Mark,

Here's how to do it in Dialogue Manager:

-SET &DATE1 = 20080101;
-SET &DATE2 = 20080412;
-SET &DIFF = YMD(&DATE1, &DATE2);

-TYPE DIFF: &DIFF


Regards,
Sean


------------------------------------------------------------------------
PROD: WebFOCUS 7.6.2 on Unix AIX/Tomcat/Servlet Mode
TEST: WebFOCUS 7.6.2 on Unix AIX/Tomcat/Servlet Mode
April 10, 2008, 03:43 PM
MarkWood
Right on. Thank you very much. Any idea why DATEDIF is not working correctly?
April 10, 2008, 03:45 PM
smiths
Mark,

We use DATEDIF in TABLE FILE, but not in DM. WF has different functions sometimes between TABLE FILE and DM to accomplish the same operation.

Regards,
Sean


------------------------------------------------------------------------
PROD: WebFOCUS 7.6.2 on Unix AIX/Tomcat/Servlet Mode
TEST: WebFOCUS 7.6.2 on Unix AIX/Tomcat/Servlet Mode
April 10, 2008, 03:51 PM
MarkWood
Thank you very much. It worked wonderfully.
April 11, 2008, 08:50 AM
jgelona
The date funcions (DATEDIF, DATEMOV, etc.) do not work with DM variable. This is documented. They work with FOCUS smart date fields. DM variables are just strings of data. For example 20080411 could be Apr 11th, 2008 or it could be 20,080,411. To use these date function, you have to first use DATECVT to convert the string to a smart date and when the computation is done convert the smart date back to a string.


In FOCUS since 1985. Prod WF 8.0.08 (z90/Suse Linux) DB (Oracle 11g), Self Serv, Report Caster, WebServer Intel/Linux.
April 11, 2008, 11:24 AM
Darin Lee
That is partly correct. the DATEDIF,DATEMOV,DATEADD et.al. function only work with smart dates. So by following your suggestion of using DATECVT to tell DM whether you are using strings or dates, it is possible to get what you need in DM with these functions. The following uses DATEMOV and DATEADD to calculate the end date of next month.
-SET &ECHO=ALL;
-SET &PBEG=DATECVT (&YYMD, 'I8YYMD', 'YYMD');
-SET &END_NEXT = DATEADD(&PBEG,'M','1');
-SET &EOM = DATEMOV(&END_NEXT.EVAL,'EOM');
-SET &ENDDTA=DATECVT (&EOM.EVAL,'YYMD','A8YYMD');
-TYPE &ENDDTA


We have been successfully using these functions in DM with no issues. Use of the DATECVT function along with them is the key.


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