Focal Point
DATEADD with strange results

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

October 31, 2007, 08:53 AM
<Ryan>
DATEADD with strange results
Hello All!

This is another DATEADD question that I can't seem to find an answer for. I guess it is more of a strange result.

All my dates are in YYMD format.

So here is my code snipet:

-SET &TODAY = &YYMD;
-SET &LASTMONTH = DATECVT((DATEADD((DATECVT(&TODAY,'I8YYMD','YYMD')),M,-1)),'YYMD','I8YYMD');
-*****
-SET &MINDATE = DATECVT((DATEMOV((DATECVT(&LASTMONTH,'I8YYMD','YYMD')),'BOM')),'YYMD','I8YYMD');
-SET &MAXDATE = DATECVT((DATEADD((DATECVT(&TODAY,'I8YYMD','YYMD')),D,-1)),'YYMD','I8YYMD');
-*****
-TYPE &YYMD &TODAY &LASTMONTH &MINDATE &MAXDATE
-EXIT


DISPLAY:
20071031 20071031 20070930 20070901 19001231

I know that when I get a date of 19001231 that it usually means an invalid date was passed. However I am passing the same value in another DATEADD function (&LASTMONTH) and it works correctly. The formula is almost identical to &LASTMONTH except for the day arithmatic instead of month.

Now, I also found out if I remove the &MINDATE line, &MAXDATE mysteriously starts displaying correctly.

I know this is Halloween and I should expect mysterious and strange things, but I could use some help figuring this one out.

Thanks,
Ryan
October 31, 2007, 09:14 AM
hammo1j
DATEMOV and DATEADD are being called without a return argument.

I know that the manual says that it's only required for MAINTAIN, but all the other subroutines tend to drop the return argument for MAINTAIN.

You could try it with the return argument in case the manual is wrong.



Server: WF 7.6.2 ( BID/Rcaster) Platform: W2003Server/IIS6/Tomcat/SQL Server repository Adapters: SQL Server 2000/Oracle 9.2
Desktop: Dev Studio 765/XP/Office 2003 Applications: IFS/Jobscope/Maximo
October 31, 2007, 09:23 AM
<Ryan>
hammo1j, thanks for the fast response. I'll try it with a return arg and let you know how it goes.

I also found this out just now. If I change the &MINDATE formula, &MAXDATE displays correctly.

What I did was take the DATEADD part of the &LASTMONTH formula and put in the place of the &LASTMONTH parm in the &MINDATE formula (basically just combined a 2 step process into 1 step). Here is the code:

-SET &TODAY = &YYMD;
-*****
-SET &MINDATE = DATECVT((DATEMOV((DATEADD((DATECVT(&TODAY,'I8YYMD','YYMD')),M,-1)),'BOM')),'YYMD','I8YYMD');
-SET &MAXDATE = DATECVT((DATEADD((DATECVT(&TODAY,'I8YYMD','YYMD')),D,-1)),'YYMD','I8YYMD');
-*****
-TYPE &YYMD &TODAY &MINDATE &MAXDATE
-EXIT

DISPLAY:
20071031 20071031 20070901 20071030

Strange, huh?!?

I would like to have it separated back out, for the readability of the code, but if I can't at least this is working.

Thanks,
Ryan
October 31, 2007, 09:29 AM
<Ryan>
Can't add a return arg. I get the following error:

(FOC275) FOCUS FUNCTION HAS INCORRECT NUMBER OF ARGUMENTS: )

Thanks,
Ryan
October 31, 2007, 09:49 AM
FrankDutch
quote:
the return argument



only works in a define, not in a set command.




Frank

prod: WF 7.6.10 platform Windows,
databases: msSQL2000, msSQL2005, RMS, Oracle, Sybase,IE7
test: WF 7.6.10 on the same platform and databases,IE7

October 31, 2007, 10:08 AM
Francis Mariani
I just tried your originally posted code and got this:
20071031 20071031 20070930 20070901 20071030
which looks right. This looks like a WF version issue.


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
October 31, 2007, 10:34 AM
Tony A
Ryan,

Stating the obvious, but if you want it "separated back out, for the readability of the code' then just rearrange the code.

I am on 7.6.2 also and get the same results as you, but having the following code works just fine - don't ask me why and just put it down to one of the oddities that we see occasionally from WebFOCUS Frowner

-SET &TODAY = &YYMD;
-SET &LASTMONTH = DATECVT((DATEADD((DATECVT(&TODAY,'I8YYMD','YYMD')),M,-1)),'YYMD','I8YYMD');
-*****
-SET &MAXDATE = DATECVT((DATEADD((DATECVT(&TODAY,'I8YYMD','YYMD')),D,-1)),'YYMD','I8YYMD');
-SET &MINDATE = DATECVT((DATEMOV((DATECVT(&LASTMONTH,'I8YYMD','YYMD')),'BOM')),'YYMD','I8YYMD');
-*****
-TYPE &YYMD &TODAY &LASTMONTH &MINDATE &MAXDATE

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
October 31, 2007, 11:10 AM
<Ryan>
Very Interesting! I hadn't thought of simply moving the statements around. Thanks Tony!

And Thanks to everyone else as well
Ryan
October 31, 2007, 11:19 AM
FrankDutch
Ryan

on 7.1.4 your original works well...

interesting program WF...keeps you have work. Wink




Frank

prod: WF 7.6.10 platform Windows,
databases: msSQL2000, msSQL2005, RMS, Oracle, Sybase,IE7
test: WF 7.6.10 on the same platform and databases,IE7