Other questions too: JMP dates always include a time, often set to zero seconds after midnight. But if the range is noon Monday to noon Monday 7 days later, how do you want to count the two half-Mondays? Or even if it is midnight at the start of Monday, should both be counted?
Counting the days might not be a bad choice if your ranges are small and not too many (poorly tested code follows):
// define an expression that answers the question
includeThisDate = Expr(
2/*monday*/<= Day Of Week( date ) <= 6/*friday*/
);
// brute force counting:
countSelectedDaysInRange = Function( {firstDate, lastDate, testexpr},
{date, count},
If( lastDate < firstDate,
Throw( "dates reversed" )
);
count = 0;
For( date = firstDate, date <= lastDate, date += In Days( 1 ),
count += (testexpr != 0)
);
count;
);
Show( 262 == countSelectedDaysInRange( 1jan2020, 31dec2020, Name Expr( includeThisDate ) ) );
Show( 104 == countSelectedDaysInRange( 1jan2020, 31dec2020, Expr( !(2/*monday*/<= Day Of Week( date ) <= 6/*friday*/) ) ) );
Show( 366 == countSelectedDaysInRange( 1jan2020, 31dec2020, 1 ) );// 2020 is leap year
Show( 0 == countSelectedDaysInRange( 1jan2020, 31dec2020, 0 ) );// no days counted
262 == countSelectedDaysInRange(01Jan2020, 31Dec2020, Name Expr(includeThisDate)) = 1;
104 == countSelectedDaysInRange(01Jan2020, 31Dec2020, Expr(!(2 <= Day Of Week(date) <= 6))) = 1;
366 == countSelectedDaysInRange(01Jan2020, 31Dec2020, 1) = 1;
0 == countSelectedDaysInRange(01Jan2020, 31Dec2020, 0) = 1;
The code above includes the last day (<= lastdate rather than <lastdate) . It starts at the first datetime value and increments by 24 hours and adds one to the count if that datetime value satisfies the expression.
From painful experience I know working with dates and times is hard to get right.
Use the builtin functions as much as possible.
Comment the code for whoever maintains it next.
Test your code carefully!
Also, if you only need a crude approximation,
(1jan2021-1jan2020)/indays(1)*5/7 == 261.428571428571
which is close to the 262 count.
edit: date difference(1jan2020,1jan2021,"day")*5/7 might look simpler for the crude answer
Craige