How to check if 2 Date Ranges Overlap in Java

Code to check if 2 date ranges overlap each other or not.


/**
* @return boolean true in case the date ranges overlap.
*/
boolean isOverLaped(Date start1,Date end1,Date start2,Date end2) throws NullPointerException{
    if ((start1.before(start2) && end1.after(start2)) || 
        (start1.before(end2) && end1.after(end2)) || 
        (start1.before(start2) && end1.after(end2))) {
        return true;
    } else {
        return false;
    }
}

0 Replies to “How to check if 2 Date Ranges Overlap in Java”

  1. Its like you read my mind! You appear to know a lot about this, like you wrote
    the book in it or something. I think that you
    could do with some pics to drive the message home a little bit, but other than that, this is magnificent blog.
    A great read. I’ll certainly be back.

  2. Spot on with this write-up, I really believe this amazing site
    needs much more attention. I’ll probably be
    back again to read through more, thanks for the information!

  3. Hey there just wanted to give you a quick heads up and let you know a few of the pictures aren’t loading correctly.
    I’m not sure why but I think its a linking issue. I’ve tried it in two different browsers and
    both show the same results.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.