Focal Point
[SOLVED]Get Last Business Day

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

January 19, 2012, 02:44 PM
Kamesh
[SOLVED]Get Last Business Day
Hi,

I would like to get the last business day by using DATEADD but it seems like not working.

Here is my code

SET HDAY=TEST
SET BUSDAYS = _MTWTF_

-SET &PREVDAY=DATEADD(&YYMD,'BD'-1);

-TYPE PREVDAY &PREVDAY
-EXIT

The above code returns 0. I tried 'WD' but even this is not working correct when I try to get previous dates.

Am I missing anything here.

Thanks,

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


WFConsultant

WF 8105M on Win7/Tomcat
January 19, 2012, 02:57 PM
Dan Satchell
From the functions manual:
quote:
Do not use DATEADD with Dialogue Manager. DATEADD requires a date to be in date format;
Dialogue Manager interprets a date as alphanumeric or numeric.

To use DATEADD in Dialogue Manager, you will need to use the DATECVT function to convert your DM date to a valid SmartDate value, then perform your DATEADD, and then convert the result back to a DM value.


WebFOCUS 7.7.05
January 19, 2012, 03:03 PM
Kamesh
Thanks Dan.

That works.


WFConsultant

WF 8105M on Win7/Tomcat
January 20, 2012, 09:47 AM
jgelona
I forget who initially suggested this, may have been Francis, but this works great. Create DEFINE FUNCTIONs for DATEADD, DATEDIF and DATEMOV for use with Dialogue Manager. Just include the following in the edasprof and it is always available:

-*
-*  Use this function to use DATEADD in Dialogue Manager
-*
 DEFINE FUNCTION UDATEADD(INDATE/A8YYMD, INUNIT/A2, INNBR/I4)
   INDATE1/YYMD    = INDATE;
   UDATEADD1/YYMD  = DATEADD(INDATE1, INUNIT, INNBR);
   UDATEADD/A8YYMD = UDATEADD1;
 END
-RUN
-*
-*  Use this function to use DATEDIF in Dialogue Manager
-*
 DEFINE FUNCTION UDATEDIF(FROM_DATE/A8YYMD, TO_DATE/A8YYMD, DIF_UNIT/A2)
   FRDT/YYMD       = FROM_DATE;
   TODT/YYMD       = TO_DATE;
   UDATEDIF1/YYMD  = DATEDIF(FRDT, INDT, DIF_UNIT);
   UDATEDIF/A8YYMD = UDATEDIF1;
 END
-RUN
-*
-*  Use this function to use DATEMOV in Dialogue Manager
-*
 DEFINE FUNCTION UDATEMOV(INDATE/A8YYMD, INMVTO/A3)
   INDATE1/YYMD    = INDATE;
   UDATEMOV1/YYMD  = DATEMOV(INDATE1, INMVTO);
   UDATEMOV/A8YYMD = UDATEMOV1;
 END
-RUN


Now you can do this:

SET HDAY=TEST
SET BUSDAYS = _MTWTF_
-RUN
-SET &PREVDAY=UDATEADD(&YYMD,'BD',-1);
-SET &LASTDAY=UDATEMOV(&YYMD,'EOM');
-SET &BDAYSDIF=UDATEDIF(&PREVDAY,&LASTDAY,'BD');
-TYPE &YYMD &PREVDAY &LASTDAY &BDAYSDIF

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.