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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:24:42+00:00 2026-06-09T01:24:42+00:00

I need a SQL query for retrieving data which is included in selected time

  • 0

I need a SQL query for retrieving data which is included in selected time period, time period is string which user selects from calendar.

For example, if user selects time period ‘2012-07-01’ to ‘2012-07-04’ and I have the following table:

ID ||  start_date  ||  end_date
 1 ||  2012-07-02  || 2012-07-04
 2 ||  2012-07-06  || 2012-08-05
 3 ||  2012-07-01  || 2012-09-01
 4 ||  2012-06-25  || 2012-09-01

If a write a sql query like this:

SELECT ID, start_date, end_date
FROM   TABLE
WHERE  start_date BETWEEN '2012-07-01' AND '2012-07-04'

This returns all rows which started from ‘2012-07-01’ to ‘2012-07-04’

ID ||  start_date  ||  end_date
 1 ||  2012-07-02  || 2012-07-04
 3 ||  2012-07-01  || 2012-09-01

But, I want all data which is included in this period, so result must be:

ID ||  start_date  ||  end_date
 1 ||  2012-07-02  || 2012-07-04
 3 ||  2012-07-01  || 2012-09-01
 4 ||  2012-06-25  || 2012-09-01

Row with ID 4 also I want to be in result, because user selected time period is under start_date and end_date.

  • 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. Editorial Team
    Editorial Team
    2026-06-09T01:24:44+00:00Added an answer on June 9, 2026 at 1:24 am
    SELECT ID, start_date, end_date
    FROM   TABLE
    WHERE  start_date BETWEEN '2012-07-01' AND '2012-07-04'
    

    You are only selecting by start date, you may ask by:

    (start_date between begin, end) OR
    (end_date   between begin, end) OR
    (start_date <= begin AND end_date >= end)
    

    so:

    (start_date between begin, end ): you have all events that starts in the range

    (end_date between begin, end): you have all events that finish in the range

    (start_date <= begin AND end_date >= end): you have all events that are active in the range

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write a SQL query which will get me those rows from
please guys, i need an sql query to select data from an access database
I need a SQL query to make all data in a column UPPER CASE?
I need to execute a SQL Query between two databases. Example: SELECT * from
I am retrieving data from a SQL table so I can display the result
I have a sql query that is retrieving results from a table but I
I have to generate a single sql query, which retrieves two columns from two
I need a SQL query that returns ContactDate, SortName, City, ContactType, and Summary from
I work on AI chat bot. I need sql query to select a single
I need an sql query to give me the following: All the values in

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.