with range
as (select cast('2023-06-17' as date) start,
           cast('2023-06-22' as date) stop
   )
select count(*) as Duration_of_Weekdays
from generate_series(
          0,
          (select datediff(day, start, stop) - 1 from range)
          )
where datepart(
          weekday,
          dateadd(day, value, (select start from range))
          ) not in ( 1, 7 )