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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T08:05:25+00:00 2026-06-16T08:05:25+00:00

I have a mySQL table to indicate weather the shop is open or closed,

  • 0

I have a mySQL table to indicate weather the shop is open or closed, based on time frames:

 shift table
--------------
 shift_id
 day_of_week    (1-7 : Monday-Sunday)
 open_time      (time, default NULL)
 close_time     (time, default NULL)
 type           (1 || 2)

Explanation of field type:
1 indicates the first timeframe within the same day and 2 indicates that the timeframe is the second timeframe within the same day.
For example shop opens on 13:00 – 15:00 AND 18:00 – 01:00.

I am getting the current day using the method below:

$jd = cal_to_jd(CAL_GREGORIAN,date("m"),date("d"),date("Y"));
    $day = jddayofweek($jd, 0);

    switch($day){
        case 0:
            $curDay = 7;
        break;
        default:
            $curDay = $day;
        break;
    }
    return $curDay;

I am getting the current time using the method below:

$timeString = "%H:%i:%s";
$curTime = mdate($timeString, time());

Complex example follows:
Current day: Monday
Current time: 02:00.
Sunday timeframe: 15:00 – 18:00 and 21:00 – 02:30.
Monday timeframe: 08:30 – 15:30.

Clearly the shift is OPEN but based on Sunday s timeframe and not on Monday s which is the current day.

What is the best way to query my table (or alter my table if needed) or the 100% accurate method to define each time if the shift is open or closed, in a given time of a given day ?

  • 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-16T08:05:26+00:00Added an answer on June 16, 2026 at 8:05 am

    This is what I was thinking:

    CREATE TABLE Shifts (
      shift_id INT AUTO_INCREMENT PRIMARY KEY,
      start_day CHAR(9) NOT NULL,
      start_time TIME NOT NULL,
      end_day CHAR(9) NOT NULL,
      end_time TIME NOT NULL
    ) ENGINE = InnoDB;
    

    Now that I think about it, I’m not really sure you even need end_day. However, using:

    INSERT INTO Shifts (
      start_day,
      start_time,
      end_day,
      end_time
    ) VALUES
    ( LOWER('Sunday'), '15:00:00', LOWER('Sunday'), '18:30:00' ),
    ( LOWER('Sunday'), '21:00:00', LOWER('Monday'), '26:30:00' ),
    ( LOWER('Monday'), '12:00:00', LOWER('Monday'), '18:00:00' ),
    ( LOWER('Tuesday'), '10:00:00', LOWER('Tuesday'), '20:45:00' ),
    ( LOWER('Wednesday'), '16:00:00', LOWER('Wednesday'), '19:30:00' ),
    ( LOWER('Thursday'), '10:00:00', LOWER('Thursday'), '17:00:00' ),
    ( LOWER('Thursday'), '19:00:00', LOWER('Friday'), '25:30:00' ),
    ( LOWER('Friday'), '16:00:00', LOWER('Saturday'), '24:30:00' ),
    ( LOWER('Saturday'), '15:00:00', LOWER('Saturday'), '20:00:00' ),
    ( LOWER('Saturday'), '18:30:00', LOWER('Sunday'), '27:00:00' )
    

    You could then use something like the following:

    SELECT DAYNAME(NOW()), start_day
    FROM Shifts
    WHERE (start_day = LOWER(DAYNAME(NOW()))
           AND start_time < CURTIME()
           AND end_time > CURTIME())
       OR (start_day = LOWER(DAYNAME(DATE_SUB(NOW(), INTERVAL 1 DAY)))
           AND start_time < ADDTIME('24:00:00', CURTIME())
           AND end_time > ADDTIME('24:00:00', CURTIME()))
    

    Which you can test out here:

    http://sqlfiddle.com/#!2/41a26/34

    And try it with different test values:

    SELECT DAYNAME(NOW()), start_day
    FROM Shifts
    WHERE (start_day = LOWER('Friday')
           AND start_time < '01:12:35'
           AND end_time > '01:12:35')
       OR (start_day = LOWER('Thursday')
           AND start_time < ADDTIME('24:00:00', '01:12:35')
           AND end_time > ADDTIME('24:00:00', '01:12:35'))
    

    http://sqlfiddle.com/#!2/41a26/33

    • 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 and would like to return the rows based on
I have mysql table that has a column that stores xml as a string.
I have MySQL InnoDB table utf-8 encoded. This table has only id and name
I have a MySql table containing stock quotes (stock_symbol, quote_date, open_price, high_price, low_price, close_price)
I have a MySQL table that looks something like this: +-----+------------+ | id |
I have a MySQL table like so; foo bar 1 21 23 17 31
I have a MySQL table called accounts . Within this table is a field
I have a MySQL table with an auto-incremented integer primary key. I want to
I have a mysql table structure like that: id int primary key name varchar
I have a MySQL table, in which I will be storing the email_id of

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.