-
checking dates
hi,
i have a pretty difficult problem i want to see if anyone has a solution to or can offer any help.
What i basically need to do is check to date ranges and see if they overlap i.e.
see if 19/11/02 to 21/11/02
overlaps 20/11/02 to 23/11/02 (which obviously it does!)
any ideas?
TIA
Nick
-
I dont have .NET in front of me, but it should be something like this:
Code:
Date1="19/11/02"
Date2="21/11/02 "
Date3="20/11/02"
Date4="23/11/02"
If (Date3>=Date1 and Date2>=Date3) or (Date4>=Date1 and Date2>=Date4) then
'They overlap
end if
-
I don't think the last post will work in the following case.
-----|-----------------|----------|------------------|-------
Date3 Date1 Date2 Date4
They obviously overlap.
I think Date3 > Date2 or Date4 < Date1 for no overlapping.
Harold Hoffman
-
this is what i've done and i think it's right:
If (startDate1 >= startDate2 And startDate1 <= finishDate2) Or (finishDate1 >= startDate2 And finishDate1 <= finishDate2) Or (startDate1 <= startDate2 And finishDate1 >= finishDate2) Or
(startDate >= startDate2 And finishDate1 <=finishDate2)
Then
haven't tried it out completely yet though :confused:
-
The most consice way should be the following.....
As there are only 6 different formations on the time line and only 2 of these are not overlapped the rest is I guess. If we have Date span A (A1[Date1] to A2[Date2]) and Date span B (B1[Date3] to B2[Date4]) the 6 are:
A1 - A2 - B1 - B2
B1 - B2 - A1 - A2
A1 - B1 - B2 - A2 -> Overlap
B1 - A1 - A2 - B2 -> Overlap
A1 - B1 - A2 - B2 -> Overlap
B1 - A1 - B2 - A2 -> Overlap
So if B1 is bigger than A2 or A1 is bigger that B2 they don't overlap, but in all other cases they do, so we should be able to just negate that:
Code:
If Not(Date3>=Date2 Or Date1>=Date4) Then
'Overlap
End if
(This is all based on the fact that we are not able to travel back in time so A2 is always bigger than A1 as B2 is bigger than B1 :))