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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excluding Sat & Sun Days in count of Days ??

Status
Not open for further replies.

TerriO

Technical User
Jan 9, 2002
84
US
Please help, I need to calculate the number of days between two date fields and exclude saturdays and sundays out of the count for Crystal 8.5 reports. Terri Mimbs
 
I got the following formula off of this board some months back. It works great, but yuo must have version 8 or newer of crystal and the loop functionality to make it work.

The variables firstday and lastday can easily be changed into parameters.

datevar firstday;datevar lastday;numbervar loop;numbervar wds; numbervar span;
firstday:=today;
if month(firstday)=12 then lastday:=date(year(firstday)+1,1,1)-1
else lastday:=date(year(firstday),month(firstday)+1,1)-1;

span:=lastday-firstday;
For loop:= 0 to span do(
if dayofweek(firstday+loop)in [2 to 6] then wds:=wds+1 else wds:=wds);

wds Software Support for Macola, Crystal Reports and Goldmine
dgilsdorf@mchsi.com
 
I am treading on territory I am not too familiar with, how would I incorporate this calculation into the formula you gave me. {LOAN.CHECK_WIRE_CLEAR_DATE} - {LOAN.CLOSE_DATE} Terri Mimbs
 
The formulas I have looked at seem to require a parameter field and now they are not reading the field as a date I need to calculate the number of working days from the result of the above formula.. Terri Mimbs
 
I found this in CR help for Datediff function:
To calculate number of working days between two dates, get the overall number of days between the dates and subtract Saturdays and Sundays. The number of Saturdays is the number of weeks taking Saturday as the first day of the week; the number of Sundays is the number of weeks taking Sunday as the first day of the week. The first parameter of DateDiff selects the interval: "d" = days, "ww" = weeks. The fourth, optional, parameter is the first day of a week: 1 = Sunday, 7 = Saturday.

Code:
formula = DateDiff("d",{Date1},{Date2}) - 
DateDiff("ww"",{Date1},{Date2},7)  -
DateDiff("ww"",{Date1},{Date2},1)
 
TerriO,

The first formula on my formulas page does exactly this. (see link mentioned above) You put your date fields on the second and third line of the formula in place of mine. No parameters are needed.

You can skip the holidays section of you aren't trying to block holidays. Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top