Welcome to WebmasterWorld Guest from 54.227.52.24

Forum Moderators: open

Message Too Old, No Replies

Storing business hours in database

     

ocon

4:54 pm on Mar 25, 2012 (gmt 0)

5+ Year Member Top Contributors Of The Month



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.

g1smd

6:24 pm on Mar 25, 2012 (gmt 0)

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



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.

topr8

7:24 pm on Mar 25, 2012 (gmt 0)

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



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.

or.
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.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month