title: compare parameter dates with dataset date field in custom code
body: <p>I need to create a report that displays net working days, excluding holidays. This needs to be a calculation or a calculated field. I have custom code to get the weekends accounted for, and have a Holiday dataset that has all the holidays I need to look for in it.</p>
  
  <p>I have set up a hidden parameter on the report for my Holiday dates. The code below runs, but I get a #Error.  As you can see have tried extracting and comparing the Year, Month and Day separately, as I thought it was maybe a date/time issue. That still produced #Error.</p>
  
  <p>Function NumWorkDays(ByRef startDate As Date,  ByRef endDate As Date) as Integer</p>
  
  <pre><code>dim i as integer
  dim x as integer
  dim totalDays as Integer
  dim WeekendDays as Integer
  dim HolidayDays as integer
  dim sDate as Date
  dim numWeekdays as Integer
  
  numWeekdays = 0
  WeekendDays = 0
  HolidayDays = 0
  sDate=startDate
  
  totalDays = DateDiff(DateInterval.Day, startDate , endDate ) + 1
  </code></pre>
  
  <p>for i = 1 to totalDays</p>
  
  <pre><code>    if DatePart(dateinterval.weekday,sDate ) = 1 then
          WeekendDays = WeekendDays + 1
      end if
      if DatePart(dateinterval.weekday, sDate ) = 7 then
          WeekendDays = WeekendDays + 1
      end if
       sDate = DateAdd("d", 1, sDate )
  next i
  </code></pre>
  
  <p>sDate=startDate</p>
  
  <p>for x = 1 to totalDays</p>
  
  <pre><code>    if DatePart(dateinterval.weekday,sDate ) &lt;&gt; 1 or 
           DatePart(dateinterval.weekday,sDate ) &lt;&gt; 7 then
          for i = 1 to Report.Parameters!HolidayParam.Count()
              if Year(Report.Parameters!HolidayParam.Value(i))=Year(sDate) and
                 Month(Report.Parameters!HolidayParam.Value(i))=Month(sDate) and 
                  Day(Report.Parameters!HolidayParam.Value(i))= Day(sDate) then           
                 HolidayDays = HolidayDays + 1
                 Exit For                
              End if
           next i
       end if
      sDate = DateAdd("d", 1, sDate )
  </code></pre>
  
  <p>next x     </p>
  
  <pre><code>numWeekdays  = totalDays - WeekendDays -HolidayDays
  return numWeekdays  
  </code></pre>
  
  <p>End Function</p>
  
  <p>Just looking for ideas as to where I have gone wrong!  Thank you!</p>