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

"Work Days" between two dates 1

Status
Not open for further replies.

Bennie47250

Programmer
Nov 8, 2001
515
US
Using Crystal version 7.0

I'm attempting to use Ken Hamady's formula ( to make this determination but I can't seem to get it to work for me.

1st, I think this is actually 2 formulas I’m not sure where the first one stops and the 2nd one begins.

2nd, I copied the first part of the formula into a new formula box and I get an error message after the “Local NumberVar i;” and before the “For i := 1 to Count (Holidays)”. The error message is “The remaining text does not appear to be part of the formula”

3rd For a start date of 12/16/04 and an end date of 12/17/04, I think Ken’s formula is going to express this as 2 days and for the purpose of this report, it should be only 1 day.

Thanks for any advice and sorry for the hand holding on this one. Seems like it should be easy enough to just copy Ken’s formula and have it work but I can’t today.
 
This part is a loop and won't work in version 7.

Local NumberVar i;
For i := 1 to Count (Holidays)
do (if Holidays in start to end then Hol:=Hol+1 );


Get rid of the array in the report header and change the formula to:

//Main formula
WhileReadingRecords;
Local DateVar Start := {StartDate}; // place your Starting Date here
Local DateVar End := {EndDate}; // place your Ending Date here
Local NumberVar Weeks;
Local NumberVar Days;
Local Numbervar Hol;


Weeks:= (Truncate (End - dayofWeek(End) + 1
- (Start - dayofWeek(Start) + 1)) /7 ) * 5;
Days := DayOfWeek(End) - DayOfWeek(Start) + 1 +
(if DayOfWeek(Start) = 1 then -1 else 0) +
(if DayOfWeek(End) = 7 then -1 else 0);

(if date(2003,12,25) in start to end then Hol:=Hol+1;
if date(2004,01,01) in start to end then Hol:=Hol+1;
//the rest of your holidays
);

Weeks + Days - Hol


Mike
 
Mike,

This seems to be working with the exception of the Holidays.
I made 12/10/2004 a holiday and ran the report for the period of last full week which includes 12/10/04 and tickets received after that date did not have their value changed.

Thoughts?

Also could you explain how this formula works?

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top