Dear MBarron,
You are right! I checked it out, and thought it was weird.
This is a standard Crystal Reports example formula!
I thought, hmm simply adding 1 should fix, since it is a datediff it must be excluding the first day. Wrong!
It fixes it for all months except for those that start or end on a Sunday, because those were right to begin with!
Also, it is right on some months. For example, your formula and my formula agree for June - 20 days for both!
In investigating this I found when you look at the help for the datediff("ww", ... 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. It is ignored for all the other interval type parameters. 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 the issue seems that for my formula to be correct I need to test to see if the First Date of the Month is a Sunday or Saturday.
Here is a corrected formula, using your bits for firstday and lastday:
//begin formula
datevar fd;
datevar ld;
fd:=date(year({currentdate}),month(currentdate),1);
if month(fd)=12 then ld:=date(year(fd)+1,1,1)-1
else ld:=date(year(fd),month(fd)+1,1)-1;
numbervar week ;
week:=(DateDiff ("d", fd, ld) -
DateDiff ("ww", fd, ld, crSaturday) -
DateDiff ("ww", fd, ld, crSunday))
+1
;
if DayOfWeek (fd) = crsunday then Week:= week - 1 ;
if DayOfWeek (fd) = crSaturday then Week:= Week - 1;
week
//end formula
Thanks so much for pointing this out - I just took the example at face value and should have investigated it more.
Glad I gave you that star now

... Rosemary Lieberman
rosemary@microflo.com,
Microflo provides expert consulting on MagicTSD and Crystal Reports.