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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:33:49+00:00 2026-06-10T15:33:49+00:00

I have a table with two fields that describe opening hours of each store

  • 0

I have a table with two fields that describe opening hours of each store – “from” and “to” in 24h format integers. I created a search page that allows user to find stores that are open at given hour.

I don’t really know how to create the SQL query, the main problem is that there are two cases.

One case is that from value is bigger than to value, for example from 23 to 5 and it gives two intervals 23 to 24 and 1 to 5.

Second case is when to value is bigger than from value (say from 8 to 22), where I get one interval.

Any idea how to create the query, that would work in those two cases?

  • 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-10T15:33:51+00:00Added an answer on June 10, 2026 at 3:33 pm

    Let’s supose this table schema:

    store
    id  fromH  toH
     1     23   5
     2      8  22
    

    and a parameter @T (the hour you are looking for)

    Then select is:

    select *
    from store
    where 
      ( fromH < toH and @t between fromH and toH ) or
      ( fromH > toH and 
             (@t between fromH and 24 OR
             (@t between 1 and toH )
      )
    

    Explaining

    Select all fields from stores that:

    • start open hour > close open hour and your hour is between both.
    • or
    • start open hour < close open hour and your hour is between open hour and 24h OR 1h and close hour.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a mysql table that has two fields that store the same type
I have one table that has two fields - ID1 and ID2 ID1 can
I have a table, myTable that has two fields in it ID and patientID
I have two tables: Folder, Files. Each table has 4 fields: ParentID, ID, Name,
So I have a table with a datestamp and two fields that I want
I have a MySQL table where there are two fields that make up the
I have a table that contains, for example, two fields that I want to
i have table with two fields competition {stateTime, endTime} when i insert to that
I have a table with two decimal(18,0) fields. I am inserting into this table,
I have a query which searches two separate fields in the same table... looking

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.