如何计算报表查看器表达式中日期之间的时间
How to calculate time between dates on a report viewer expression
我有一个程序使用报表查看器向用户显示各种类型的数据,我需要其中一个来(基本上)计算两个没有周末的日期之间的天数(即:从星期五到星期一,应该显示 2 而不是 4)。
到目前为止,我可以计算它,但有周末。
如果有人知道怎么做,我将不胜感激。
代码示例:(我在其中一个表中使用的公式作为表达式)
CInt(Avg(DateDiff(dateinterval.DayOfYear,
Fields!DataEntregue.Value,
Fields!DataPrevista.Value,
FirstDayofWeek.Monday)))
从 this question 开始,我已将 Alec Pojidaev(未接受)的回答转换为 VB。我还返回了一个整数而不是双精度:
Public Shared Function GetBusinessDays(startD As DateTime, endD As DateTime) As Integer
Dim calcBusinessDays As Double = 1 + ((endD - startD).TotalDays * 5 - (startD.DayOfWeek - endD.DayOfWeek) * 2) / 7
If CInt(endD.DayOfWeek) = 6 Then
calcBusinessDays -= 1
End If
If CInt(startD.DayOfWeek) = 0 Then
calcBusinessDays -= 1
End If
Return CInt(calcBusinessDays)
End Function
用法:
GetBusinessDays(date1, date2)
顺便说一句,以后您要查找的是如何计算[在此处输入语言] 中两个日期之间的工作日数。对此进行快速网络搜索会给您带来很多答案。
我有一个程序使用报表查看器向用户显示各种类型的数据,我需要其中一个来(基本上)计算两个没有周末的日期之间的天数(即:从星期五到星期一,应该显示 2 而不是 4)。
到目前为止,我可以计算它,但有周末。
如果有人知道怎么做,我将不胜感激。
代码示例:(我在其中一个表中使用的公式作为表达式)
CInt(Avg(DateDiff(dateinterval.DayOfYear,
Fields!DataEntregue.Value,
Fields!DataPrevista.Value,
FirstDayofWeek.Monday)))
从 this question 开始,我已将 Alec Pojidaev(未接受)的回答转换为 VB。我还返回了一个整数而不是双精度:
Public Shared Function GetBusinessDays(startD As DateTime, endD As DateTime) As Integer
Dim calcBusinessDays As Double = 1 + ((endD - startD).TotalDays * 5 - (startD.DayOfWeek - endD.DayOfWeek) * 2) / 7
If CInt(endD.DayOfWeek) = 6 Then
calcBusinessDays -= 1
End If
If CInt(startD.DayOfWeek) = 0 Then
calcBusinessDays -= 1
End If
Return CInt(calcBusinessDays)
End Function
用法:
GetBusinessDays(date1, date2)
顺便说一句,以后您要查找的是如何计算[在此处输入语言] 中两个日期之间的工作日数。对此进行快速网络搜索会给您带来很多答案。