Alex Rivera | Logout

.NET Date Compare: Count the amount of working days since a date?

Asked 2008-10-03T06:21:12.720
11

What's the easiest way to compute the amount of working days since a date? VB.NET preferred, but C# is okay.

And by "working days", I mean all days excluding Saturday and Sunday. If the algorithm can also take into account a list of specific 'exclusion' dates that shouldn't count as working days, that would be gravy.

Thanks in advance for the contributed genius.

Edit
Report

1 Answer

4

Here is a sample of Steve's formula in VB without the holiday subtraction:

Function CalcBusinessDays(ByVal DStart As Date, ByVal DEnd As Date) As Decimal

        Dim Days As Decimal = DateDiff(DateInterval.Day, DStart, DEnd)
        Dim Weeks As Integer = Days / 7
        Dim BusinessDays As Decimal = Days - (Weeks * 2)
        Return BusinessDays
        Days = Nothing
        Weeks = Nothing
        BusinessDays = Nothing

End Function
answered 2011-08-02T15:22:15.370

Your Answer