ExtensionMethod.NET Home of 846 C#, Visual Basic, F# and Javascript extension methods


Gets the next occurrence day of the week specified.


Public Module DateTimeExtensions

	''' <summary>
	''' Returns the next occurrence of the day of the week specified.
	''' </summary>
	<Extension()> _
	Public Function GetNext(ByVal dt As DateTime, ByVal dayOfWeek As DayOfWeek) As DateTime
		Dim daysToAdd As Integer = 0
		If dt.DayOfWeek < dayOfWeek Then
			daysToAdd = dayOfWeek - dt.DayOfWeek
			daysToAdd = (7 - dt.DayOfWeek) + dayOfWeek
		End If
		Return dt.AddDays(daysToAdd)
	End Function

End Module


#1/1/2010#.GetNext(DayOfWeek.Friday) ' Returns #1/5/2010#

Author: MattMc3

Submitted on: 5 nov 2010

Language: VB

Type: System.DateTime

Views: 3344