homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

Storing business hours in database

5+ Year Member

Msg#: 4433222 posted 4:54 pm on Mar 25, 2012 (gmt 0)

I have a large database of different businesses around the world that I would like to include their business hours. I'm wondering how to best store their hours in the database.

I would like to be able to nicely output their hours on my website, something like:

Sun: Closed
Mon-Fri: 7AM-9PM
Sat: 10AM-6PM

Sun-Sat: 24hrs

Sun: Closed
Mon: 12PM-6PM
Tue: Closed
Wed: 10AM-12PM, 3PM-7PM
Thu-Sat: 12PM-7PM

While at the same time I am looking to be able to perform database queries to search for businesses that are currently open.

Right now a single row on one table is all that is needed for each listing and ideally I would like to keep it that way.

While I don't want to display it on the website, I also realize for things like performing the currently open searches, I need to somehow account for different timezones.



WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

Msg#: 4433222 posted 6:24 pm on Mar 25, 2012 (gmt 0)

Firstly, use 24 hour time. It will make things a lot easier.

You'll also need a list of places that observe DST and the dates that apply for each one... otherwise your "open now" indicator will be off by an hour for 5 to 7 months of the year.


WebmasterWorld Senior Member topr8 us a WebmasterWorld Top Contributor of All Time 10+ Year Member

Msg#: 4433222 posted 7:24 pm on Mar 25, 2012 (gmt 0)

either have 4 fields for each day.
first open,first closed, second open, second close
(that's assuming that shops only ever (potentially) close for lunch and not twice a day)
so you have an extra 28 fields in the table per store
then build a php function to calculate the opening times on the page.

there can only be so many open/close sequences.
create an extra table with one row for each variation and reference the id field in your businesses table.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved