Focal Point
[SOLVED] Finding next specific weekday

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

July 21, 2011, 10:23 AM
Nancy Walter
[SOLVED] Finding next specific weekday
I have a delivery date that I then need to find the next specific weekday. For example, if a delivery date is 20110728 and my service date is on Tuesday, I need to find the date of that following Tuesday 20110802.

Is this possible? I know about the DATEMOV/NBD function but it's not necessarily the next business day but more a specific day of the week after that date that I need.

Thanks

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


Version 7.6.9
Windows
All (excel, PDF, powerpoint, html, active html)

July 21, 2011, 11:32 AM
Severus.snape
Hi,

Here's a couple of ideas..

This one is simple but I am not sure why it is picking up the BD which is 2 weeks from now...
I had to substract one week from the result ..

  

SET BUSDAYS = __T____
TABLE FILE CAR
PRINT
COMPUTE NEW_DATE/YYMD = '&DATEYYMD'; 
-*COMPUTE NEW_DATE/WT = DATECVT(HIRE_DATE, 'I6YMD', 'YYMD'); AS 'DOW' 

COMPUTE NBD/YYMD = DATEMOV(NEW_DATE, 'NBD');
COMPUTE PBD/YYMD = DATEMOV(NEW_DATE, 'PBD'); 
COMPUTE NEXTSERVICEDT/YYMD = DATEADD(NBD,'D',-7);

BY CAR NOPRINT

END
-EXIT


Another way is to find out the week day of the current day or your delivery date and find out the next service day based on the week day..i.e whether it is a Tuesday or Wed etc....

  

-SET &SERVICE_DAY = 'TUESDAY';

TABLE FILE CAR
PRINT
COMPUTE NEW_DATE/YYMD = '20110728';
COMPUTE NEW_DATE1/I6YMD = DATECVT(NEW_DATE,'YYMD','I6YMD');
COMPUTE DOWK1/A4 = DOWK(NEW_DATE1,'A4');
COMPUTE BUSDAY/I1 = IF '&SERVICE_DAY' EQ 'TUESDAY' THEN DECODE DOWK1(MON 1 TUE 7 WED 6 THU 5 FRI 4 SAT 3 SUN 2 ) 
ELSE DECODE DOWK1(MON 2 TUE 1 WED 7 THU 6 FRI 5 SAT 4 SUN 3 ) ;
COMPUTE NEXTSERVICEDT/YYMD = DATEADD(NEW_DATE,'D',BUSDAY);

BY CAR NOPRINT

END
-EXIT


You have to extend the IF THEN in the compute to cover all the week days...

thanks
Sashanka


WF 7.7.03/Windows/HTML,PDF,EXL
POC/local Dev Studio 7.7.03 & 7.6.11
July 21, 2011, 02:56 PM
Nancy Walter
I used your second example and it works great with the exception that it's calculating the DOWK for the wrong day. For example, your code produces a day of FRI for 11/07/28 which is actually a THU. Any clue how to fix that? If I can, then this solves my problem.

NEW_DATE NEW_DATE1 DOWK1 BUSDAY NEXTSERVICEDT
2011/07/28 11/07/28 FRI 4 2011/08/01
2011/07/28 11/07/28 FRI 4 2011/08/01
2011/07/28 11/07/28 FRI 4 2011/08/01
2011/07/28 11/07/28 FRI 4 2011/08/01
2011/07/28 11/07/28 FRI 4 2011/08/01
2011/07/28 11/07/28 FRI 4 2011/08/01
2011/07/28 11/07/28 FRI 4 2011/08/01
2011/07/28 11/07/28 FRI 4 2011/08/01
2011/07/28 11/07/28 FRI 4 2011/08/01
2011/07/28 11/07/28 FRI 4 2011/08/01

Many Thanks!!!
Nancy


Version 7.6.9
Windows
All (excel, PDF, powerpoint, html, active html)

July 21, 2011, 03:03 PM
Severus.snape
Strange .when I run the same code ..i am getting correct day.

NEW_DATE NEW_DATE1 DOWK1 BUSDAY NEXTSERVICEDT
2011/07/28 11/07/28 THU 5 2011/08/02
2011/07/28 11/07/28 THU 5 2011/08/02
2011/07/28 11/07/28 THU 5 2011/08/02
2011/07/28 11/07/28 THU 5 2011/08/02
2011/07/28 11/07/28 THU 5 2011/08/02
2011/07/28 11/07/28 THU 5 2011/08/02
2011/07/28 11/07/28 THU 5 2011/08/02
2011/07/28 11/07/28 THU 5 2011/08/02
2011/07/28 11/07/28 THU 5 2011/08/02
2011/07/28 11/07/28 THU 5 2011/08/02


WF 7.7.03/Windows/HTML,PDF,EXL
POC/local Dev Studio 7.7.03 & 7.6.11
July 25, 2011, 06:44 AM
GamP
That's because you have different settings for defcent, I guess.
If you change the 2nd compute to read:
COMPUTE NEW_DATE1/I8YYMD = NEW_DATE;
you'll both have the same output.


GamP

- Using AS 8.2.01 on Windows 10 - IE11.
in Focus since 1988
July 25, 2011, 10:44 AM
j.gross
Once you have a "smart" date, it's easy. No date-conversion functions are required.
-DEFAULT &DAY='TUE';
-* use CAR to generate 15 consecutive dates.
DEFINE FILE CAR
DATE1/WMDYY WITH MODEL= 
  IF DATE EQ 0 
    THEN '&DATEMDYY' 
    ELSE DATE + 1;
-*******************************************
W1/WT=DATE;
W2/WT='&DAY';
-* compute how many days to add (0 TO 6)
N/I5=IMOD(7+W2-W1,7,'I5');
DATE2/WMDYY=DATE1+N;
-*******************************************
END
TABLEF FILE CAR
LIST DATE1 W1 W2 N DATE2
IF RECORDLIMIT EQ 15
END

The code has no magic constants. (It does not depend on the convention for assigning weekday numbers, and would work whether the range were 0 to 6 or 1 to 7; and regardless of which days are assigned the start and end positions in the week)
July 28, 2011, 11:18 AM
Nancy Walter
Thank you GamP! That worked perfectly! Appreciate the help!


Version 7.6.9
Windows
All (excel, PDF, powerpoint, html, active html)