Storing Business Hours in a Database

后端 未结 6 668
迷失自我
迷失自我 2020-12-04 07:05

I\'m currently trying to work out the best way to store a business\' hours of operation in a database.

For example:

Business A has the following hours of ope

6条回答
  •  借酒劲吻你
    2020-12-04 07:40

    It sort of depends on what you need to store it for and what the real-world data could look like.
    If you need to be able to determine if the business is open at a certain point then it may be a bit awkward to query the scheme as laid out. More importantly, though, is: Would you ever need to cater for a mid-day closure?

    Some options include;

    • A scheme like what you have, but with the option to have multiple periods for the same day. It would cater for the lunch break, but would make it awkward to run a query that gives you the opening hours for a given day, say for presentation to a user.
    • A bitmap style approach; "000000000111111110000000" for 9-5. The downside to this approach is that you have to choose a specific granularity, i.e. whole hours or half-hours or, indeed, minutes. The finer the granularity, the harder the data is to read for a human. You could use bitwise operators to store this value as a single number rather than a string of integers, but again it hurts legibility.

提交回复
热议问题