Focal Point
[CLOSED] Function DATEDIFF

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

August 28, 2009, 10:44 AM
roby
[CLOSED] Function DATEDIFF
Hi!
I am trying to get the difference between two dates using DATEDIFF but get wrong result.
Here is the code that I am using.

DEFINE FILE TOT
DTINIZ /YYMD = &DATAINI;
DTFINE /YYMD = &DATAFIN;
APPO_DIF_NEW /I4L= DATEDIF(DTINIZ,DTFINE,'BD');
END
-*
TABLE FILE TOT
PRINT APPO_DIF_NEW
ON TABLE HOLD AS 'LUNA'
END

When my begining date is 20090105 and end date is 20090106, I am getting the difference as 1.
The corect result is 0. Infact in Italy the 20090106 is not work.
How should I Know the calendar used?

Thanks for any help

This message has been edited. Last edited by: Kerry,
August 28, 2009, 11:23 AM
GamP
Roby,
The difference between the two dates you mention is very much 1.
But, I think you wanted not the absolute difference, but the difference in business days.
For that to accomplish, I refer to the documentation on this subject.
There is quite a lot of doc to be found on business days and how to implement it, and on top of that there is this little booklet, called '(Almost) 1001 Ways to Work with DATES in WebFOCUS'. This is very valuable literature for the WebFocus developer. It costs only $25, orderable through the IBI web site.


GamP

- Using AS 8.2.01 on Windows 10 - IE11.
in Focus since 1988
September 01, 2009, 07:01 AM
Jinx
quote:
APPO_DIF_NEW /I4L= DATEDIF(DTINIZ,DTFINE,'BD');


Is this maybe a situation where you need a holiday table / file - so that public holidays are excluded from datediff type calculations. Something like SET HDAY = YOURDATES?


7.6.11
Windows
HTML, PDF, Excel etc
DevStudio/Webfocus/Focus IBM
SQL Server 2000 / 2008
DB2
September 01, 2009, 09:38 AM
Danny-SRL
Roby,

Look in the functions manual.
You will find:
quote:

Setting Business Days to Reflect Your Work Week.
The following designates work days as Sunday, Tuesday, Wednesday, Friday, and Saturday:
SET BUSDAYS = S_TW_FS


and for the holiday file:

quote:

Specifying Holidays
You can specify a list of dates that are designated as holidays in your company. These
dates are excluded when using functions that perform calculations based on working days.

To define a list of holidays, you must:
1. Create a holiday file using a standard text editor.
Dates must be in YYMD format.
Dates must be in ascending order.
Each date must be on its own line.
The file name must be HDAYxxxx.ERR, where xxxx can be any 4 characters.

2. Select the holiday file by issuing the SET command with the HDAY parameter.
SET HDAY = xxxx



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

September 01, 2009, 09:47 AM
Jinx
Sorry! Should really have given more info, just never sure if I am totally off the mark or not Razzer.


7.6.11
Windows
HTML, PDF, Excel etc
DevStudio/Webfocus/Focus IBM
SQL Server 2000 / 2008
DB2
September 02, 2009, 09:19 AM
jgelona
Also, when setting up the holiday file, it has to be in the correct location and the documentation (at least in 7.1.3) was not very clear as to where that was. After I created the file and put it where the documentation said, it was not working. I had to call IBI to find the correct location for our installation.

Also, be sure and update it every year.

And one other thing to remember. When using DATEDIF with BD, if either date passed to DATEDIF is a non-business day (assuming that business days are MTWTF) the date is internally adjusted to the next business day. For example, assuming that Labor Day, Sep 7th, 2009 is in the holiday file:
DAYS1/I8=DATEDIF(20090907,20090903,'BD');
DAYS2/I8=DATEDIF(20090914,20090907,'BD');

DAYS1 will be 2 days and DAYS2 will be 4 days. In both computations, 20090907 is adjusted forward to 20090908.

The results will be the same if instead of 2009/09/07, one uses the 5th or 6th since those Sat & Sun. They are adjusted to the 8th, then the calculation is done.

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


In FOCUS since 1985. Prod WF 8.0.08 (z90/Suse Linux) DB (Oracle 11g), Self Serv, Report Caster, WebServer Intel/Linux.
September 02, 2009, 10:12 AM
Francis Mariani
quote:
the correct location
What is the correct location?


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 02, 2009, 10:23 AM
GinnyJakes
/WebFOCUS/ibi/srv76/wfs/bin


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 02, 2009, 10:30 AM
Francis Mariani
Ginny, thanks for the response. I was trying to make a point that if someone mentions there is a "correct location" perhaps they should mention where it is Smiler


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 03, 2009, 10:25 AM
jgelona
Francis,

My point was that at the time I built my file the "correct location" was dependent on one's installation platform. That is Linux/Unix had one path and Windows another. I guess IBI has finalized that it will always be in the wfs/bin folder but my path is /opt/ibi/713/ibi/srv71/wfs/bin (don't ask me why, I didn't install the WebFOCUS Reporting Server). I went back and checked my old problem report and the pages on IBIs website that gave me the incorrect information are no longer available.

Also, just to add to the topic. All of the DATE functions, when using BD or WD will adjust dates that are not Business or Week days to the next Business or Week day before doing the function. So if one wants to add 3 business days to Sep 5, 2009, the result will be Sep 11,2009. Sep 5th will be adjusted to Sep 8th.


In FOCUS since 1985. Prod WF 8.0.08 (z90/Suse Linux) DB (Oracle 11g), Self Serv, Report Caster, WebServer Intel/Linux.