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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:16:02+00:00 2026-05-17T15:16:02+00:00

I have an application storing the times a restaurant is open: My code to

  • 0

I have an application storing the times a restaurant is open:

My code to get the currently open restaurants. My SQL query (simplified) looks like

SELECT * 
  FROM `restaurants` r 
 WHERE r.from <= NOW()  
   AND r.to >= NOW();

The problem here is, there’s an entry which rolls over — it’s for a restaurant open from 11 AM to 3 AM the next day.

What would be a good query to capture that particular restaurant?

  • 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-05-17T15:16:02+00:00Added an answer on May 17, 2026 at 3:16 pm

    In pseudo code:

    if (close > open) {
        store_is_open = (open <= now <= close)
    } else {
        store_is_open = (open <= now || now <= close)
    }
    

    Converting that to SQL:

    WHERE IF(
        r.from < r.to,
        NOW() BETWEEN r.from AND r.to,
        NOW() >= r.from OR NOW() <= r.to
    )
    

    You might also want to check for places which are open 24 hours. The below code assumes that you would set the from and to times to be the same (eg: from midnight to midnight)

    WHERE IF(
        r.from = r.to,
        1,
        IF(
            r.from < r.to,
            NOW() BETWEEN r.from AND r.to,
            NOW() >= r.from OR NOW() <= r.to
        )
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have an application that will be collecting data and storing it in local
I am looking for a method of storing Application Messages, such as You have
I have a C# application that includes the following code: string file = relativePath.txt;
In my spring application context file, I have something like: <util:map id="someMap" map-class="java.util.HashMap" key-type="java.lang.String"
I have an application where I get a vector<string> . I need to iterate
I have created an application which requires the reloading of an image several times
I have an application which takes a string value of the form %programfiles%\directory\tool.exe from
I have a Java application that's very String-heavy - it takes a feed of
I have a rails application which is still showing the cachebusting numeric string at
I have a string representing a path. Because this application is used on Windows,

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.