Dear Saint1234,
I am curious, if your date range begins on a weekend date, do you want that date considered as one of the weekends?
The reason I ask is because of an anomolay with the datediff function. This was discovered by Mbarron and myself some time ago and the back and forth on that can be found in thread149-304415
If you read the help on datediff, you will see that it states:
//begin quote:
Use DateDiff with the "ww" parameter to calculate the number of firstDayOfWeek's occurring between two dates. For the DateDiff function, the "ww" parameter is the only one that makes use of the firstDayOfWeek argument... For example, if firstDayOfWeek is crWednesday, it counts the number of Wednesday's between startDateTime and endDateTime.
It does not count startDateTime even if startDateTime falls on a Wednesday, but it does count endDateTime if endDateTime falls on a Wednesday...
//end quote
So keeping the above in mind, how could we solve this?
The following formula adds a day as appropriate when the start date is on a weekend.
//Begin formula
Local DateVar Start := Date(2004,2,7);
Local DateVar End := date(2004,2,29);
local numbervar sats := DateDiff ("ww", Start, End, crSaturday);
local numbervar suns := DateDiff ("ww", Start, End, crSunday);
if dayofweek(start) = 7 then suns := suns + 1;
if dayofweek(start) = 1 then sats := sats + 1;
sats + suns
//end formula
Hope that helps,
ro
Rosemary Lieberman
rosemary@microflo.com,
Microflo provides expert consulting on MagicTSD and Crystal Reports.