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


Check if a given date is within another specified date range.


<Extension()> _
Public Function isDateBetween(ByVal inBetweenDate As DateTime, ByVal startDate As DateTime, ByVal endDate As DateTime) As Boolean
    Return inBetweenDate >= startDate AndAlso inBetweenDate <= endDate
End Function


' Is the date within the allowed range.
Dim startdate  As New DateTime(2000, 01, 01)
Dim enddate  As New DateTime(2020, 01, 01)
If DateTime(2009, 10, 06).isDateBetween(startDate,endDate) Then
' Is in range
' Out of range
End If

Author: Jon Burrows

Submitted on: 6 okt 2009

Language: VB

Type: System.DateTime

Views: 3603