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

  • SEARCH
  • Home
  • 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

Related Questions

I have written a code that searches specific string from database table.what i want
I have an Oracle table which contains event log messages for an application. We
I have some event handler on a boundary class that manages a persistence mechanism
In .NET, Windows Forms have an event that fires before the Form is loaded
I have a simple event handler with a ItemAdding event that changes a column
I have a table in an Oracle database that contains actions performed by users
I have a process that needs to select rows from a Table (queued items)
I have a table SIGNUPS, where I register all signups to a specific event.
I have a SQL table Events (ID int, Event int, StartTime datetime, Duration int
I have an Events table whose goal is to store actions done by web

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.