I have a travel app and allow users to pick travel dates by using a date range picker: https://flatpickr.js.org/examples/#range-calendar
Date Range Picker Value = 2020-06-22 to 2020-06- 27
What is the best way to store this data in my database?
I'm currently doing it like this..
3 columns in the database.
- trip_date
name="trip_date"
- start_date
- end_date
I break apart the Range Picker Value like this:
$dates = explode('to', $request->trip_date);
$startDate = trim($dates[0]);
$endDate = trim($dates[1]);
Then save the dates like this:
$travelDates= TravelDate::create([
'trip_date' => $request->trip_date,
'start_date' => $startDate,
'end_date' => $endDate,
...
I guess the only reason to store the Full trip_date from the range picker would be for easy return output to the user, but how would you format 2020-06-22 to 2020-06- 27 to a more readable format like m-d-Y to m-d-Y? the double dates and the "to" is throwing me off..
I love the user experience of using a date range picker, but think it might be best to Drop trip_date column and only store start_date and end_date.
Curious how others handle this.