E
E
enchikiben2013-08-02 14:50:23
MySQL
enchikiben, 2013-08-02 14:50:23

Request a sample of the work of the store

Good evening! There is a structure that stores the time of the store:

ID time_start (hour number) time_stop (hour number) day_start (number of the day of the week) day_stop (sequential number of the day of the week)
one 12 one 7 4
2 12 2 5 6


you need to choose so that the end time is taken into account, for example, if for the first entry, if Friday has already arrived (day number 5), but the time has not yet passed through the end time, then select this entry.

Tell me how you can choose this way, if possible at all, or tell me a more successful structure for storing the store's work time.

Thank you!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Anton Anton, 2013-08-02
@Fragster

maybe then it’s better to change the structure of the table, for example
day-time - activity
0-0-0
0-6-1
0-22-0
1-6-1
...
well, change the number of the day of the week to a date to the heap (let's say + to 0001 -01-01 00:00:00). And then fasten the regulated calendar, as in 1sk ...

P
Petrusha Ukropov, 2013-08-02
@artishok

$now = current time;
$day = current day;
SELECT * FROM shop WHERE time_start>=$now AND time_stop<=$now AND day_start>=$day AND day_end<=$day

R
rozhik, 2013-08-04
@rozhik

There are several shopId, startT, endT records for each store. Where startT, endT are the time in seconds since Monday 00:00.
It is indexed well, allows you to set any schedule with weekly periodicity.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question