Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 44643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:41:03+00:00 2026-05-10T15:41:03+00:00

In MySQL, If I have a list of date ranges (range-start and range-end). e.g.

  • 0

In MySQL, If I have a list of date ranges (range-start and range-end). e.g.

10/06/1983 to 14/06/1983 15/07/1983 to 16/07/1983 18/07/1983 to 18/07/1983 

And I want to check if another date range contains ANY of the ranges already in the list, how would I do that?

e.g.

06/06/1983 to 18/06/1983 = IN LIST 10/06/1983 to 11/06/1983 = IN LIST 14/07/1983 to 14/07/1983 = NOT IN LIST 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T15:41:04+00:00Added an answer on May 10, 2026 at 3:41 pm

    This is a classical problem, and it’s actually easier if you reverse the logic.

    Let me give you an example.

    I’ll post one period of time here, and all the different variations of other periods that overlap in some way.

               |-------------------|          compare to this one                |---------|                contained within            |----------|                   contained within, equal start                    |-----------|          contained within, equal end            |-------------------|          contained within, equal start+end      |------------|                       not fully contained, overlaps start                    |---------------|      not fully contained, overlaps end      |-------------------------|          overlaps start, bigger            |-----------------------|      overlaps end, bigger      |------------------------------|     overlaps entire period 

    on the other hand, let me post all those that doesn’t overlap:

               |-------------------|          compare to this one      |---|                                ends before                                  |---|    starts after 

    So if you simple reduce the comparison to:

    starts after end ends before start 

    then you’ll find all those that doesn’t overlap, and then you’ll find all the non-matching periods.

    For your final NOT IN LIST example, you can see that it matches those two rules.

    You will need to decide wether the following periods are IN or OUTSIDE your ranges:

               |-------------|    |-------|                       equal end with start of comparison period                          |-----|   equal start with end of comparison period 

    If your table has columns called range_end and range_start, here’s some simple SQL to retrieve all the matching rows:

    SELECT * FROM periods WHERE NOT (range_start > @check_period_end            OR range_end < @check_period_start) 

    Note the NOT in there. Since the two simple rules finds all the non-matching rows, a simple NOT will reverse it to say: if it’s not one of the non-matching rows, it has to be one of the matching ones.

    Applying simple reversal logic here to get rid of the NOT and you’ll end up with:

    SELECT * FROM periods WHERE range_start <= @check_period_end       AND range_end >= @check_period_start 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 65k
  • Answers 65k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer {% if user.get_profile.has_feature_enabled %} May 11, 2026 at 11:16 am
  • added an answer You can add '| nothing' to TALES expressions or use… May 11, 2026 at 11:16 am
  • added an answer a subclassed dispatcher ( quoted from http://cslai.coolsilon.com/2009/03/28/extending-zend-framework/ ) class Coolsilon_Controller_Dispatcher… May 11, 2026 at 11:16 am

Related Questions

In MySQL, If I have a list of date ranges (range-start and range-end). e.g.
If I have a table in MySQL which represents a base class, and I
If I have an mssql varchar[1024] that is always empty in a table, how
Say if I had a table of books in a MySQL database and I
How do I check if an index exists on a table field in MySQL?
Say I want to check if a record in a MySQL table exists. I'd
Does anybody know if there is a way to make autocompletion work in MySQL
How can ALTER be used to drop a column in a MySQL table if
In Mysql Administrator, when doing backups, what exactly is Compatibility Mode? I'm trying to
In mysql, how do I get the primary key used for an insert operation,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.