VB.Net overlap dates.

By krirkjung

If you want to check overlap between dates you can use this function

Public Shared Function IsOverlapDate(ByVal D1Begin As Date, ByVal D1End As Date, ByVal D2Begin As Date, ByVal D2End As Date) As Boolean

If Date.Compare(D1Begin, D2End) <= 0 And Date.Compare(D1End, D2Begin) >= 0 Then

Return True

End If

Return False

End Function

‘_____________________________________________________

Then try to test The function

Dim DBegin1 as New Date(2008,2,14)

Dim DEnd1 as New Date(2008,3,22)

Dim DBegin2 as New Date(2008,3,10)

Dim DEnd2 as New Date(2008,4,21)

Dim DBegin3 as New Date(2008,4,2)

Dim DEnd3 as New Date(2008,4,3)

Dim blnResult as Boolean

blnResult = IsOverlapDate(DBegin1,DEnd1,DBegin2,DEnd2) ‘ It is return true

blnResult = IsOverlapDate(DBegin3,DEnd3,DBegin2,DEnd2) ‘ It is return true

blnResult = IsOverlapDate(DBegin1,DEnd1,DBegin3,DEnd3) ‘ It is return false

Tags:

Leave a Reply