If you made your calculation on a period begginig on a wednesday and ending on another wednesdy, it will not be usefull, but if you do on a period beginning on a monday and ending on a thursday, this will substract the difference between thos different days in the week to have a multiple of 7 to make the integer division.

Example: from a monday to a tuesday, the difference between those date will be 7*w+1 where w is a number of complet week.

As the function weekday return 0 for sunday, 1 for mondays, ..., the (SDate.weekday-FDate.weekday) will return 1

tuesday - monday = 2 - 1 = 1. So the complet expression will be:

- Code: Select all
`((SDate.diffdays(FDate)-(SDate.weekday-FDate.weekday))/7)*2=`

(((7*w+1)-(tuesday - monday))/7)*2=

((7*w+1-(2-1))/7)*2=

((7*w+1-1)/7)*2 =

((7*w)/7)*2=

(w)*2 = 2w

Second example:

starting on a sunday, ending on a friday:

- Code: Select all
`((SDate.diffdays(FDate)-(SDate.weekday-FDate.weekday))/7)*2=`

(((7*w+5)-(friday-sunday))/7)*2=

((7*w+5-(5-0))/7)*2=

((7*w+5-5)/7)*2 = 2w

The problem is that we do not have count the first sunday, that is why we have this line:

- Code: Select all
`if(FDate.weekday == 0) WEDays++;`

and so the result will be: 2w + 1.

This is the same problem if we have the second date as a saturday

I see yet that there will be a mistake if we begin with a saturday and finish with another saturday: in so the two if must be rewrite as this:

- Code: Select all
` if(SDate.weekday != FDate.weekday){`

if(SDate.weekday == 6) WEDays++;

if(FDate.weekday == 0) WEDays++;

}

I hope this will help you and resolve your problem.

Marc Lambrigger