SQL for Opening Hours

后端 未结 2 1288
余生分开走
余生分开走 2020-12-13 05:23

In my shops database I need to have the opening hours. Do you have an idea how i can implement this in my dB?

The opening hours are from Monday to Sunday, each day c

2条回答
  •  失恋的感觉
    2020-12-13 05:25

    What type of database are you using? If it's mysql, put in a field of type "time". Then you can pass it the times and do basic sql time manipulations on them. This whole post assumes mysql.

    If there is only one store and you know it will never grow, just make a table called times where you keep the times the store is open. Then, if you want to see if the store is open just check the current time against one of the ranges in the database.

    If there is more than one store, make a table called "times" and a table called "stores". In the times table, columns can be "open" and "close" with an id called "store_id". The stores table needs an id too. Then, you can just say:

    "SELECT open, close FROM times WHERE store_id=x"
    

    This will give you ALL the time ranges associated with the particular store.

提交回复
热议问题