Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store opening weekdays in a database

I have a group of checkboxes where the user selects some of the weekdays (the opening days of a store). How can I save the selected days? Should I save something like 0111111 (zero means closed on sunday) on the same field and split the result when reading the data? Or create a field for each day and store 0 or 1 on each (weird)?

like image 577
JoaoPedro Avatar asked Apr 28 '10 15:04

JoaoPedro


1 Answers

The first approach saves space, the second improves performance while retrieving data, especially if you need to filter by individual weekday. It also makes the queries that manipulate weekdays a way clearer. You have to decide what is more important to you based on the application's logic.

In general, I'd use field-per-day solution.

like image 55
a1ex07 Avatar answered Sep 29 '22 21:09

a1ex07