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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:19:58+00:00 2026-06-08T00:19:58+00:00

I am going to need to return a special value to tell me if

  • 0

I am going to need to return a special value to tell me if the current time is within opening hours:

In table places

ID    OPEN     CLOSE  
1     14:00    16:00  
2     12:00    15:00
3     10:00    14:00

I need to return in the query a special field: PLACE_IS_OPEN – true or false.

so that the returned result when the time is 14:35 is:

ID      PLACE_IS_OPEN
1       1
2       1
3       0

What would be a descent way to go about this?

  • 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-08T00:20:00+00:00Added an answer on June 8, 2026 at 12:20 am

    Test that TIME(NOW()) lies between the open and close times and return its boolean result as a column. This will work as-is if your OPEN,CLOSE are MySQL DATETIME or TIME columns.

    SELECT
      ID,
      OPEN,
      CLOSE,
      CASE WHEN TIME(NOW()) BETWEEN `OPEN` AND `CLOSE` THEN 1 ELSE 0 END AS PLACE_IS_OPEN
    FROM yourtable
    

    If these are character columns rather than proper TIME types, you will need STR_TO_TIME() to convert them

      CASE WHEN TIME(NOW()) BETWEEN TIME(STR_TO_DATE(`OPEN`, '%H:%i')) AND TIME(STR_TO_DATE(`CLOSE`, '%H:%i')) THEN 1 ELSE 0 END AS PLACE_IS_OPEN
    

    And MySQL should allow you to simplify the CASE statement away, since the BETWEEN will return a 0 or 1 as it is:

    SELECT
      ID,
      OPEN,
      CLOSE,
      (TIME(NOW()) BETWEEN TIME(STR_TO_DATE(`OPEN`, '%H:%i')) AND TIME(STR_TO_DATE(`CLOSE`, '%H:%i'))) AS PLACE_IS_OPEN
    FROM yourtable
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need help understanding whats going on in the function, especially the return statements.
I simply need to return a list of all days within a month. I'm
I'm going to need to write a program that takes a list of persons
I am going to need to do some development with Eclipse JDT while on
I have a class which is going to need to use the strategy design
I'm creating a reporting application, and our customers are going to need to generate
i need an sql script that is going to change the datasource of all
I need to know what is going wrong here, when I try to run
I need to learn couchbd and have been going through tutorials on views. I
I need to do some clean up work when I am going to terminate

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.