Focal Point
DATEADD bug/feature FWIW

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

January 17, 2008, 09:51 AM
jgelona
DATEADD bug/feature FWIW
I just found out that when using DATEADD with business days, if the date being added to is not a business day, DATEADD adjusts it to the next business day, then does the addition. Keep in mind that if you use a holiday file, holidays are not business days.

For example, if I add 2 business days to Jan 1st, 2008 (which is in my holiday file) you get Jan 4th, not Jan 3rd. This is because DATEADD adjusts Jan 1st to Jan 2nd then adds 2 business days.

Likewise, if I add 2 business days to Nov 1, 2008 (which is a Saturday), I get Nov 5th, not Nov 4th. This is because DATEADD adjusts Nov 1 to Nov 3rd then adds 2 business days.

I opened a problem report with IBI and found out this is an undocumented feature of the DATEADD function, not a bug.

I was wondering, for those of you with the manual about using dates (I don't remember the title but it was something like "1000-and-1 ways to use Dates" or "Everything you wanted to know about dates and but was afraid to ask"), is this feature documented there?


In FOCUS since 1985. Prod WF 8.0.08 (z90/Suse Linux) DB (Oracle 11g), Self Serv, Report Caster, WebServer Intel/Linux.
January 17, 2008, 10:17 AM
Prarie
On page 123 of Almost 1001 Ways to work with Dates...it says the BD Letters instructs the DATEADD function to adjust the date by business-days which are Monday thru Friday.


In Focus since 1993. WebFOCUS 7.7.03 Win 2003
But does it say anything about adjusting the input/source date, the date that is being adjusted, to the next business day? The reason I ask is that is appears to do this only when adding days. Consider the following:
-SET &RUNDT1=DATECVT(DATEADD(DATECVT(20080101,'I8YYMD','YYMD'),'BD',-2),'YYMD','I8YYMD');
-SET &RUNDT2=DATECVT(DATEADD(DATECVT(20080101,'I8YYMD','YYMD'),'BD',2),'YYMD','I8YYMD');
-TYPE &RUNDT1  &RUNDT2 

Gives 20071228 for &RUNDT1 and 20080104 for &RUNDT2.

Since Jan 1 2008 is a holiday and not a business day, it seems to me, that to be consistent, when I substract 2 business days, the source date (20080101) should be adjusted to 20071231, then substract the 2 days to give 20071227 not 20071228.


In FOCUS since 1985. Prod WF 8.0.08 (z90/Suse Linux) DB (Oracle 11g), Self Serv, Report Caster, WebServer Intel/Linux.
Not specifically that I've seen...this is a 340 page book full of examples and tips...it's kinda hard to find all notations....Perhaps someone out there has read the entire book. Wink


In Focus since 1993. WebFOCUS 7.7.03 Win 2003