/ Published in: Visual Basic
VB Extension Method for Weekday difference
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<System.Runtime.CompilerServices.Extension()> Function WeekdayDiff(ByVal dte As DateTime, ByVal interval As Integer) As DateTime Dim days As Integer Dim counter As Integer If interval = 0 Then Return dte Exit Function ElseIf interval > 0 Then days = 1 counter = 1 Else days = -1 counter = -1 End If Do Until days = interval + counter dte = dte.AddDays(counter) If (dte.DayOfWeek < DayOfWeek.Saturday AndAlso dte.DayOfWeek > DayOfWeek.Sunday) Then days = days + counter End If Loop Return dte End Function