Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculate Business Day

Status
Not open for further replies.

H1004

MIS
Oct 28, 2003
136
0
0
US
I have a problem calculating business day because it is short on one day:

For example:
TODAYDATE/WYYMD=&BEG;
DIFF/I8=DATEDIF(TODAYDATE, ENDDATE, 'BD');

Suppose TODAYDATE = 20041211 (Saturday)
ENDDATE = 20041218 (Saturday)
The diff will come out as 4; however, I wanted to come out as 5. The answer 5 will give me Monday, Tuesday, Wednesday, Thursday, and Friday.
I understand why it is giving me 4 because
20041217(Friday) - 20041213(Monday) = 4 days

Is there a code that work around this problem in order for me to get an answer of 5.
Thank you,
 
I tried using the the method where if the enddate is on a weekday, then I'll increment the result to 1, but if it lands on a Saturday or Sunday, then I'll leave it alone. However, I tried using the following function to determine the weekday, but it is not working for me. Am I doing something wrong?

ENDDATE/WYYMD=REQUESTED_DATE;
TODAYDATE/WYYMD=&BEG;
DIFF/I8=DATEDIF(TODAYDATE, ENDDATE, 'BD');
DAYIND/A12= DOWKL(ENDDATE, DAYIND);
 
Actually, I try the following code, and it displays the day of the week now instead of blank, but the data is wrong...It seems to always be a day ahead. So instead of Friday, it would have a result of Saturday. Here is my code:

ENDDATE/I6YMD = REQUESTED_DATE;
DAYOW/A3 = DOWK(ENDDATE,DAYOW);

Any reason why??
 
What release are you running? I tried the following in releases 4.2.1 through 5.3:

Code:
-SET &BEG = '20041211'; 
-SET &ENDDATE = '20041218';
DEFINE FILE CAR
TODAYDATE/WYYMD WITH COUNTRY='&BEG';
ENDDATE/YYMD WITH COUNTRY= '&ENDDATE';
DIFF/I8 WITH COUNTRY=DATEDIF(TODAYDATE, ENDDATE, 'BD');
END
TABLE FILE CAR
PRINT TODAYDATE ENDDATE DIFF 
IF COUNTRY EQ 'ENGLAND'
END

and got the following:
Code:
 TODAYDATE        ENDDATE         DIFF
 ---------        -------         ----
 SAT, 2004/12/11  2004/12/18         5
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top