Focal Point
[SOLVED]DATEADD Function

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

July 03, 2012, 10:18 AM
Jay Potter
[SOLVED]DATEADD Function
I am using the following command

-SET &LAST_SATURDAY = DATEADD(&YYMD, 'D', -3)

the ECHO displays this
-SET &LAST_SATURDAY = DATEADD(20120703, 'D', - 3);

LAST_SATURDAY ends up being 20120700

Shouldn't it end up being 20120630? Do I need to use a different Date Format?

This message has been edited. Last edited by: Jay Potter,


WebFocus 8.1.5
iSeries/Windows
DB2/SQL/Access
Dev Studio
App Studio
Maintain
ReportCaster
July 03, 2012, 10:43 AM
Mighty Max
DATEADD uses smart dates. As a workaround you can use DATECVT to convert the date to a smart date. Then use DATEADD to subtract the days. Then uses DATECVT again to change the smart date into a numeric date.

  
-SET &LAST_SATURDAY = DATECVT(DATEADD(DATECVT(&YYMD,'I8YYMD','YYMD'),'D',-3),'YYMD','I8YYMD');
-TYPE &LAST_SATURDAY



WebFOCUS 8.1.05M Unix Self-Service/MRE/Report Caster - Outputs Excel, PDF, HTML, Flat Files
July 03, 2012, 10:48 AM
Prarie
DATEADD has issues with Dialog Manager. Can you do this in a define instead.


In Focus since 1993. WebFOCUS 7.7.03 Win 2003
OR you can do that. Wink
Thanks! The DATECVT worked. It's great when they document where you can use some in some places but not others.


WebFocus 8.1.5
iSeries/Windows
DB2/SQL/Access
Dev Studio
App Studio
Maintain
ReportCaster
You should get the book 1001 Ways to Work with Dates in WebFocus. It's documented there that it does not work with Dialog Manager. It's a great thing to have.
Thanks! I will look into it.


WebFocus 8.1.5
iSeries/Windows
DB2/SQL/Access
Dev Studio
App Studio
Maintain
ReportCaster
Prarie, I hope that book documents that you can use Date-Time functions in Dialog Manager when used in conjunction with DATECVT, e.g.
-SET &TEST1 = DATECVT(DATEADD(DATECVT(&YYMD,'I8YYMD','YYMD'),'D',-3),'YYMD','I8YYMD')



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
The other option is to use the legacy date function aymd.

Its all documented in the functions manual, it will pay to have a good look.

-SET &LAST_SATURDAY = AYMD(&YYMD,-3,'I8YYMD') ;

-TYPE &LAST_SATURDAY



Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

I just had this issue today and in 5 minutes I found the correct code to resolve it. The information here just saved my bacon (again) and made it look like I know what I'm doing. Smiler

Thanks to all who post here on Focal Point.

Norb


prod:7.6.9, win2k3 mre, caster, bid, devstudio 7.6.9
It would be a whole lot easier to create DEFINE FUNCTIONs for DATEADD, DATEMOV and DATEDIF. If done properly, anything you can do in a TABLE request with these function can be done in Dialogue Manager using the same syntax.


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

DEFINE FUNCTION UDATEADD(INDATE/A8YYMD, INUNIT/A2, INNBR/I4)
INDATE1/YYMD    = INDATE;
UDATEADD1/YYMD  = DATEADD(INDATE1, INUNIT, INNBR);
UDATEADD/A8YYMD = UDATEADD1;
END
-RUN

-SET &DATE1 = UDATEADD(&YYMD, 'M', -3);

-TYPE &YYMD - &DATE1




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