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

isDateBetween

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

Source

<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

Example

' 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
Else
' Out of range
End If

Author: Jon Burrows

Submitted on: 6 okt. 2009

Language: VB

Type: System.DateTime

Views: 4816