How to store the "time period" in the database is more reasonable?

in development, there are some scenarios where we need to store information for a time period in the database. For example, an event has a start time and an end time, and we can store it in the database with two fields such as startDate and endDate. But if this period of time is periodic or intermittent.

for example:

Store the class time of a course, which is taught every Monday, Wednesday, and Friday

in that case, how should the table structure of the database be designed reasonably?

create 7 Boolean fields that represent Monday to Sunday?


using two tables to design will have better scalability.
1. Course schedule, record the introduction of the course
2. Schedule courses, record class start time, end time, etc.

this kind of time is convenient for new requirements in the future, such as statistics, or check-ins will be added in the future.

so I mean. Use a table to record time periods, and there is an one-to-many relationship.


is based on demand
as you said, if you only have a period of time, you can start time + end time, or start time + duration

      

then if you want to design one that is compatible with various modes, it may be more complicated.
readability, space, and speed are all fluctuating

.

because I only see one such requirement, I think you can use the binary method to calculate.

for example, in 135th class, the stored binary data is 10101000 ;

then check every time whether there is a class on Wednesday:

   

Menu