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;

9 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.

  4. Hey I think You forgot to put one condition that start1.after(start2) && end1.before(end2) like for e.g 7:00 to 10:30 compared tp 6:00 to 12:00

Leave a Reply

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