Frank
Frank

Reputation: 2357

How to setup business according to its business-hour?

Am trying to schedule different type of business according to its business-hour

want to create 2 tables
1. Business
2. Business Hours (according to sun, mon, tue, wed, thus, fri, sat)

Example: Business name: "Sam's salon"
Business Hours: mon 10am-2pm , tue 11am-5pm, wed 1pm-5pm, .....

plz suggest a relative table structure, where each business point to its business hours.

Upvotes: 0

Views: 75

Answers (2)

Robin Castlin
Robin Castlin

Reputation: 10996

Basicly I'd use:

business_id - int (11)
weekday - enum('sun','mon','tue','wed','thu','fri','sat')
start_unix - int(11)
end_unix - int(11)

A day have 86 400 seconds. You could simply save the seconds passed from the start of the day.

To fetch that certain day's opentimes you'd do something like:

$str_week_day = strtolower(date('D'));

SELECT start_unix, end_unix
FROM business_hours
WHERE business_id = {$int_business_id} AND weekday = '{$str_week_day}'

Then to get the time, you'd so a:

$str_start = date('Ha', strtotime('today') + $row->start_unix);
$str_end = date('Ha', strtotime('today') + $row->end_unix);

echo "{$str_start}-{$start_end}";

On input/creating of a row, you'd simply do a:

// $_POST['start_unix'] could be 09:50am
$int_start_unix = strtotime($_POST['start_unix']) - strtotime('today');

Upvotes: 2

James Williams
James Williams

Reputation: 4216

A Relational Model would be as Follows:

Business Table
---------------
id - Primary Key - Auto Increment
Business Name

Busines Hours Table
-------------------
id - Primary Key - Auto Increment
Business id - Foreign Key (Business Table id field)
WeekDay (either number 0-6 or text for day)
Start Hour - datetime format
End Hour - datetime format

For weekday number system 0 would be Sunday and 6 would be Saturday. Or custom if you so choose.

This would allow for you to easily add additional business information like address/phone without needing multiple rows for one store.

Upvotes: 2

Related Questions