S
S
Sergey Erzhovich2021-11-02 15:46:27
MySQL
Sergey Erzhovich, 2021-11-02 15:46:27

How to build a database structure with a weekly schedule, taking into account weekends and breaks?

For example, there are services that provide services, I want to attach to them a schedule with an operating mode that takes into account weekends, breaks (there may be several), the beginning and end of the working day.

For example, the following data:

Shawarma:
Tue-Fri: 09:00-18:00 Break: 12:00-12:30, 15:30-15:55
Sat: 09:00-15:00 Break: 12:00-12 :30
Mon-Sun: day off

or for example such an option

Hamburgers:
Mon-Sun: around the clock, Break: 23:50-00:10, 06:25-06:40

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Neverov, 2021-11-02
@Drilled-prog

Two tables. The first contains the work schedule on a specific day for a specific company:

+------------+-------------+------------+----------+
| company_id | day_of_week | start_time | end_time |
+------------+-------------+------------+----------+
|          1 |           0 | 09:00      | 18:00    |
|          1 |           1 | 09:00      | 18:00    |
+------------+-------------+------------+----------+

The second contains information about breaks, the structure is exactly the same.
+------------+-------------+-------------+-----------+
| company_id | day_of_week | start_break | end_break |
+------------+-------------+-------------+-----------+
|          1 |           0 | 12:00       | 12:30     |
|          1 |           0 | 15:30       | 15:55     |
+------------+-------------+-------------+-----------+

You will already collect the work schedule from the data that you receive in the table. If some day of the week is a day off, you can either not create this day in the table, or fill it with null (start, end). The first option is preferable.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question