0

I'm developing a website and need, for each user, to store in my database the dates where each of his items is available.

The problem is that the dates are not following each other; for example, an item can be available the 6,7,9 of August but not the 8.

The table would look like this :

                  -----------------------------------------------------
                  | item | owner | dates_where_item_is_available | ID |
                  -----------------------------------------------------
   For example :  | car  | 56    | 15/03/2019, 18/04/2019,       | 7  |
                  |      |       | 02/05/2019                    |    |

So I'm looking for a way to store these lists of dates: I heard that storing a string containing a list of dates is bad, but I don't know what the alternatives are...

What would be the best way to store these dates?

1 Answers1

1
  1. store them as dates
  2. create another table maybe called available_date or similar

    available_date


item_id
begin_date
end_date

here, you would store the id from the other table as a FK the begin_date and end_date allow you to cover a contiguous range of dates in fewer rows, but also allows you to create a new row if there is a gap.

Randy
  • 16,480
  • 1
  • 37
  • 55