Focal Point
[CLOSED] Move to previous weekday

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

November 22, 2010, 01:42 PM
Norb Eckert
[CLOSED] Move to previous weekday
Hi All,

All I want to do is, within a loop, move from a day to the prior weekday, execute some code, move to the prior weekday, execute some code etc. Moving to the prior weekday seems to fail when around month boundaries. I cannot for the life of me determine why this is not working. Please note the following:

20101031 is a Sunday so moving to the PWD should give 20101029, a Friday, but it produces a result of 20101028, a Thursday. If I change &NEWDATE to 20101030, a Saturday, I get a result of 20101028.

If I change &NEWDATA to 20101101 then the code works properly. It seems that if the date I'm trying to convert/move falls on a weekend then the code fails. Do you think I'm gonna have to code something that looks at the day of the week and then move one day at a time and lok at the day again etc. I'm stumped.

  

SET BUSDAYS = _MTWTF_
-SET &NEWDATE = '20101031';
-SET &NEWDATE = DATECVT((DATEMOV(DATECVT(&NEWDATE,'I8YYMD','YYMD'), 'PWD')), 'YYMD', 'I8YYMD');
-TYPE &NEWDATE;



Any help would be appreciated.

Thanks,

Norb

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


prod:7.6.9, win2k3 mre, caster, bid, devstudio 7.6.9
November 22, 2010, 01:58 PM
Tony A
Hi Norb,

Try using the previous business day instead of prior weekday -

-SET &NEWDATE = DATECVT((DATEMOV(DATECVT(&NEWDATE,'I8YYMD','YYMD'), 'BD-')), 'YYMD', 'I8YYMD');

previous weekday (WD-) also works but would not cater for holidays.

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 
November 22, 2010, 02:18 PM
Norb Eckert
Hi Tony,

I tried your suggestion and it does indeed work when the date I am moving from is a weekend day but fails when the day is a weekday. I suspect I'm going to have to do some very specific checking on the day of the week and branch off accordingly. Confused

Thanks for your prompt reply.

Norb


prod:7.6.9, win2k3 mre, caster, bid, devstudio 7.6.9
November 22, 2010, 11:20 PM
Dan Satchell
Looks to me like there is a bug when using the 'PWD' parameter with DATEMOV. Here's a work-around that seems to work. Subtract one day from the start date and then use DATEMOV with the 'WD-' parameter. This will move to the previous workday if the current date is a weekend, but leave the date where it is if it's a weekday.

-SET &NEWDATE = '20101031';
-SET &NEWDATE = DATECVT((DATEMOV(DATECVT(&NEWDATE, 'I8YYMD', 'YYMD') - 1, 'WD-')), 'YYMD', 'I8YYMD');
-TYPE &NEWDATE



WebFOCUS 7.7.05