Results 1 to 5 of 5

Thread: checking dates

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870

    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

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367
    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

  3. #3
    Member
    Join Date
    Sep 2002
    Posts
    37
    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

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870
    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

  5. #5
    Registered User
    Join Date
    Nov 2002
    Location
    Växjö, Sweden
    Posts
    314
    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 )
    Last edited by Athley; Jan 8th, 2003 at 02:08 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width