Focal Point
[CLOSED] DATEADD One Month

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

October 27, 2014, 11:55 AM
ColdWhiteMilk
[CLOSED] DATEADD One Month
If I understand correctly,
DATEDD(&YYMD,'M',1)
will add one month to the &YYMD value.

But what does WebFOCUS consider one month equal to? 30 days? Same day, but prior month?

Just curious.

This message has been edited. Last edited by: <Kathryn Henning>,


Production - 7.6.4
Sandbox - 7.6.4
October 27, 2014, 01:39 PM
MartinY
It use an internal matrix to reduce (or add) the number of days in a month to go to the previous or the next one without creating an invalid date.

Per example:
DEFINE FILE CAR
MTH1/YYMD=DATEADD('2014/03/31', 'M', -1);
MTH2/YYMD=DATEADD('2014/03/31', 'M', -2);
MTH3/YYMD=DATEADD('2014/03/31', 'M', -3);

MTH4/YYMD=DATEADD('2014/03/25', 'M', -5);

END
TABLE FILE CAR
BY COUNTRY NOPRINT
BY MTH1
BY MTH2
BY MTH3
BY MTH4
WHERE COUNTRY EQ 'FRANCE';
END
-RUN


Is resulting in:
MTH1       MTH2       MTH3       MTH4 
2014/02/28 2014/01/31 2013/12/31 2013/10/25 



WF versions : Prod 8.2.04M gen 33, Dev 8.2.04M gen 33, OS : Windows, DB : MSSQL, Outputs : HTML, Excel, PDF
In Focus since 2007
October 27, 2014, 02:09 PM
Tom Flynn
The date has to be a "smart date", not a text string, which is what &YYMD, and, any Dialogue Manger value is unless converted:

-SET &MTH_1 = DATECVT(DATEADD(DATECVT(&YYMD,'I8YYMD','YYMD'),'M',+1), 'YYMD', 'I8YYMD');
-TYPE &MTH_1
-EXIT


Tom Flynn
WebFOCUS 8.1.05 - PROD/QA
DB2 - AS400 - Mainframe
October 27, 2014, 02:21 PM
MartinY
Was just to show the result of month shift with different input date values.
Was easier, I've been lazy Wink
But true, the input of DATEADD, must be a smartdate.
DEFINE FILE CAR
DTE/YYMD=&YYMD;
DT_1 /YYMD=DATEADD(DTE, 'M', -1);
END
TABLE FILE CAR
PRINT DTE DT_1
BY COUNTRY
WHERE COUNTRY EQ 'FRANCE';
END



WF versions : Prod 8.2.04M gen 33, Dev 8.2.04M gen 33, OS : Windows, DB : MSSQL, Outputs : HTML, Excel, PDF
In Focus since 2007
October 28, 2014, 07:00 AM
ColdWhiteMilk
ok, so it is not just subtracting 30, for example, which is what I was trying to confirm.

Thank you.


Production - 7.6.4
Sandbox - 7.6.4
October 28, 2014, 07:31 AM
MartinY
And it's smart enough to take care of the leap years as per below example. (I know I used a text date, but it's just to show Cool)
DEFINE FILE CAR
MTH1/YYMD=DATEADD('2012/03/31', 'M', -1);
END
TABLE FILE CAR
BY COUNTRY NOPRINT
BY MTH1
WHERE COUNTRY EQ 'FRANCE';
END
-RUN



WF versions : Prod 8.2.04M gen 33, Dev 8.2.04M gen 33, OS : Windows, DB : MSSQL, Outputs : HTML, Excel, PDF
In Focus since 2007
October 28, 2014, 11:06 AM
susannah
seems to be a theme today. Tom, look up the AYMD and AYM functions, for working with &var dates, adding and subtracting. You'll enjoy knowing about them.




In Focus since 1979///7706m/5 ;wintel 2008/64;OAM security; Oracle db, ///MRE/BID