Reputation: 21
I have a program that uses report viewers to show various types of data to the user, and I need one of them to (basically) calculate the days between two dates WITHOUT weekends (i.e: from Friday to Monday, should show 2 and not 4).
So far, I can calculate it but with the weekends.
If anyone knows how, I'll appreciate it.
Code sample:(the formula i use on one of my tables as a expression)
CInt(Avg(DateDiff(dateinterval.DayOfYear,
Fields!DataEntregue.Value,
Fields!DataPrevista.Value,
FirstDayofWeek.Monday)))
Upvotes: 1
Views: 329
Reputation: 15774
From this question, I have converted Alec Pojidaev's (not accepted) answer to VB. I also returned an integer instead of double:
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
Usage:
GetBusinessDays(date1, date2)
BTW, in the future, what you were looking for was how to calculate number of business days between two dates in [enter language here]. A quick web search for this would have brought you to a number of answers.
Upvotes: 1