VB Extension Method WeekdayDiff


/ Published in: Visual Basic
Save to your folder(s)

VB Extension Method for Weekday difference


Copy this code and paste it in your HTML
  1. <System.Runtime.CompilerServices.Extension()>
  2. Function WeekdayDiff(ByVal dte As DateTime, ByVal interval As Integer) As DateTime
  3.  
  4. Dim days As Integer
  5. Dim counter As Integer
  6.  
  7. If interval = 0 Then
  8. Return dte
  9. Exit Function
  10. ElseIf interval > 0 Then
  11. days = 1
  12. counter = 1
  13. Else
  14. days = -1
  15. counter = -1
  16. End If
  17.  
  18. Do Until days = interval + counter
  19. dte = dte.AddDays(counter)
  20. If (dte.DayOfWeek < DayOfWeek.Saturday AndAlso dte.DayOfWeek > DayOfWeek.Sunday) Then
  21. days = days + counter
  22. End If
  23. Loop
  24.  
  25. Return dte
  26.  
  27. End Function

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.