【发布时间】:2019-09-01 13:23:33
【问题描述】:
我需要创建一个显示净工作日(不包括节假日)的报告。这需要是计算或计算字段。我有自定义代码来计算周末,并且有一个假期数据集,其中包含我需要在其中查找的所有假期。
我在报告中为我的假期日期设置了一个隐藏参数。下面的代码运行,但我得到一个#Error。如您所见,尝试分别提取和比较年、月和日,因为我认为这可能是日期/时间问题。这仍然产生#Error。
函数 NumWorkDays(ByRef startDate As Date, ByRef endDate As Date) as Integer
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
对于 i = 1 到 totalDays
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
sDate=开始日期
对于 x = 1 到总天数
if DatePart(dateinterval.weekday,sDate ) <> 1 or
DatePart(dateinterval.weekday,sDate ) <> 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 )
下一个
numWeekdays = totalDays - WeekendDays -HolidayDays
return numWeekdays
结束函数
只是寻找关于我哪里出错的想法!谢谢!
【问题讨论】:
-
我已经单步执行了代码,它会在 If Year(Report.Parameters...etc...) 产生 #Error 如果我使用 "If Report.Parameters!HolidayParam .Value(i)=sDate then"
标签: date parameters compare ssrs-2012