VB.Net overlap dates.

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



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: