Link to home
Start Free TrialLog in
Avatar of tjyoung
tjyoung

asked on

Before I get too far.. best way to save dates data

Hi,
I am keeping a record of days a store is closed for the year ie:

2017-01-01
2017-01-03
2017-01-04
2017-01-09

So I'm using multi-datepicker which allows me to select closed days for the year, and inserts them into a hidden text field to include along with the rest of my form's POST submission.

Like this:  2017-01-01,2017-01-03,2017-01-04,2017-01-09 etc.

Was thinking I'd use 'explode' and insert each into the DB separately into a date column and dealer_id.

Then I began to wonder wouldn't I be better off to simply insert the values as an 'array' something like this into a single record for the year ie:
closed: ["2017-01-01","2017-01-03","2017-01-04","2017-01-09"]
dealer_id: XXXXXX

Going forward I'd be checking the table daily to see if the above 'array' contains todays date in case they are closed.

So my question is:
What is the best way to store that kind of data? As a comma-separated string or a separate entry per date?
Avatar of Shaun Vermaak
Shaun Vermaak
Flag of Australia image

I now there are drawbacks to this approach but it is what I like to do.

For these configuration values I create a Config table, each record has Key and Value and I would just save it as JSON to the Value table with Key of "Closed" or whatever.
"closed" : ["2017-01-01","2017-01-03","2017-01-04","2017-01-09"]

Open in new window


I am sure there are better approaches
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tjyoung
tjyoung

ASKER

Great article and very relevant. Thanks again.
Glad to help!  All the best for 2017, ~Ray