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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:09:53+00:00 2026-05-27T02:09:53+00:00

Consider the SQL query below: SELECT * FROM opening_hours WHERE week_day = WEEKDAY(NOW()) +

  • 0

Consider the SQL query below:

SELECT * FROM opening_hours  
        WHERE week_day = WEEKDAY(NOW()) + 1 
              AND open_hour =< date_format(now(),'%H:%i') 
              AND close_hour >= date_format(now(),'%H:%i')

open_hour / close_hour fields are TIME type.

I am using MySQL.

Suppose that open_time is “18:00”, close_time is “02:00”, current time is “22:41”. We have a separate DB record for the close_time (cause it’s after midnight), but we will never get it in the result, because the close_time “02:00” is NOT greater than the current time, “22:41”.

Also if current time is “01:00”, we will get the NEXT day values, because the weekday doesn’t match.

Solution?

Would you rather store these values in integer (minutes), so the php is able to process these values directly, without any conversion?

For example…

Current time:

$timearr = explode(':',date("w:H:i"));
$currenttime = ($timearr[0]) * 1440 + $timearr[1] * 60 + $timearr[2] 

Minimal value of current time = 0 (Sun, 00:00), max value is 10079 (Sat, 23:59)

In the database, the stored open/close time values may be between 0 and 11519 (Sat, 47:59)

Now suppose, that the current time is “Sun, 01:00” (first day of week), executing the above coversion this value is 60; and the open/close times for last day of week (Saturday) are set to “17:00” and “02:00” (which is actually Sunday), stored in the DB as 9660 and 10200 (Saturday, 26:00). In this case, the above query will not find the record we need (Sat, 17:00, 02:00), because we probably don’t have any open_time less than “02:00” (120). To solve this, we convert “Sun, 01:00” to “Sat, 25:00”, by adding 7*1440 (a whole week) to the $currenttime, which will result 10140. Then DB query like this:

SELECT open_time,clos_time FROM open_hours 
    WHERE (open_time <= $currenttime 
         AND close_time >= $currenttime)
         OR (open_time <= $currenttime +10080
         AND close_time >= $currenttime + 10080);

Or what is alternative and neater solution?

  • 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-27T02:09:54+00:00Added an answer on May 27, 2026 at 2:09 am

    Use INT since not all databases support DATE fields, or support them in the same way. INT is much more portable and it’s just as easy to figure out your date with the integer timestamp if you choose to go that route.

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

Sidebar

Related Questions

Consider the following SQL Server 2005/2008 query: Select [UID], [DESC] From SomeTable Order By
Consider the following 3 standard statements $queryString = SOME SQL SELECT QUERY; $queryResult =
First off, here's my SQL query: SELECT research_cost, tech_name, (SELECT research_cost FROM technologies WHERE
Consider this query: SELECT F1,F2 FROM TABLE GROUP BY F1 Selecting F1 is valid,
Consider this query: WITH Scores (score) AS ( SELECT CAST(score AS INTEGER) FROM (
Let's consider such query: SELECT * FROM ( SELECT YEAR(OrderDate) [Year], MONTH(OrderDate) [Month], SubTotal
Consider the following SQL: SELECT mov FROM movie WHERE mov IN ( SELECT mov
consider my sql query below; it is calling sum twice for the same argument.
Consider the following sql server query , DECLARE @Table TABLE( Wages FLOAT ) INSERT
Consider this T-SQL: CREATE USER my_test_user WITHOUT LOGIN; SELECT USER_NAME(), USER, SUSER_SNAME(),SYSTEM_USER, suser_name(); EXECUTE

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.