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 178275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:12:10+00:00 2026-05-11T14:12:10+00:00

I have an Event table that specifies a date range with start_date and end_date

  • 0

I have an Event table that specifies a date range with start_date and end_date fields. I have another date range, specified in code, that defines the current week as ‘week_start’ and ‘week_end’.

I’d like to query all Events for the week. The cases seem to be:

  • Event begins and ends within the week
  • Event begins before the week, but ends within the week
  • Event begins within the week, but ends after the week
  • Event begins before the week and also ends after the week
  • Events that neither reside within, nor overlap the week at all are ignored

I’m attempting to come up with a query that can handle all these cases. So far I’ve only been able to get cases that handle the week overlaps, or events that are fully internal; Essentially, too many records, or none at all.

  • 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-11T14:12:10+00:00Added an answer on May 11, 2026 at 2:12 pm
    (event.start BETWEEN week.start AND week.end) OR (week.start BETWEEN event.start AND event.end) 

    In simple words, either a week starts during the event, or an event starts during the week.

    Let’s check it:

    Event begins and ends within the week

    The event starts during the week.

    Event begins before the week, but ends within the week

    The week starts during the event.

    Event begins within the week, but ends after the week

    The event starts during the week.

    Event begins before the week and also ends after the week

    The week starts during the event.

    Note that BETWEEN in expressions above is used just for the sake of brevity.

    Strict expression looks like this:

    (event.start >= week.start AND event.start < week.end) OR (week.start >= event.start AND week.start < event.end) 

    , provided that week.end is a week.start + INTERVAL 7 DAY.

    I. e. if you week starts of Sun, 0:00:00, then it should end on next Sun, 0:00:00 (not on Sat, 0:00:00)

    This expression looks more complex than the one which is commonly used:

    event.start < week.end AND event.end > week.start 

    , but the former is more efficient and index friendly.

    See these articles in my blog for performance comparisons:

    • Overlapping ranges: SQL Server
    • Overlapping ranges: MySQL
    • Overlapping ranges: Oracle
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 112k
  • Answers 112k
  • 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
  • Editorial Team
    Editorial Team added an answer Depending on the database engine you are using, there can… May 11, 2026 at 9:55 pm
  • Editorial Team
    Editorial Team added an answer If you do want to enable parts of Firebug globally,… May 11, 2026 at 9:55 pm
  • Editorial Team
    Editorial Team added an answer That is the Unicode Byte Order Mark interpreted as something… May 11, 2026 at 9:55 pm

Related Questions

Using SQL Server 2005, I have a table where certain events are being logged,
this is my very first post! I'm pretty desperate so I'm going above and
I have a web application that needs to fire off a long-running SQL Server
I have searched around, and it seems that this is a limitation in MS

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.