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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:50:14+00:00 2026-05-22T11:50:14+00:00

I have a database table storing opening hours of a shop as a time

  • 0

I have a database table storing opening hours of a shop as a time range as a VARCHAR like ‘9am-5pm’ and ‘9am-3pm, 5pm-11pm’. I want to compare these opening hours with the current time, so if the current time is 2pm, I will use PHP to echo a text stating that the shop is now open, and if the current time is 11.30pm, the shop will be shown as closed.

  1. How do I compare the current time with the opening hours time range in the tables
  2. Is my method of storing time range suitable?

I’m using Codeigniter, so if theres useful functions do let me know too!

  • 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-22T11:50:15+00:00Added an answer on May 22, 2026 at 11:50 am

    You should use 2 columns (one for open time, one for close time) both using the TIME datatype: http://dev.mysql.com/doc/refman/5.1/en/time.html

    By doing that, you can then use BETWEEN and NOW(): SELECT * FROM shop WHERE CAST(NOW() AS TIME) BETWEEN open_time AND close_time;

    Edit to include table definition:

    CREATE TABLE shop_hours (
      shop_id INT UNSIGNED NOT NULL,
      day_of_week INT UNSIGNED NOT NULL, -- 0-6
      open_time TIME NOT NULL,
      close_time TIME NOT NULL,
      PRIMARY KEY(shop_id, day_of_week, open_time, close_time)
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database table storing opening hours of a restaurant as a time
I have a MySQL database table that has a VARCHAR field storing a date
I have a database table which storing shop list for users. I wish to
i have database table like this +-------+--------------+----------+ | id | ip | date |
that my problem: I have database table like that: id (AI) market_id 1 6
I have a database with one of the table storing articles. For every article
Ok, I have a database with with a table for storing classified posts, each
I have a database that contains a table for storing URL Images (since storing
I have a database with a table, storing changes in account-balance across a couple
I have on my database a table with one column storing XML data. Due

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.