Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

daugaard47's avatar

Date Range Picker Storing Data

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.

  1. trip_date name="trip_date"
  2. start_date
  3. 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.

0 likes
1 reply
Sinnbeck's avatar

I would drop the trip_date column. Having a string like that in the database makes little sense as you can easily construct it from the other 2 fields. Also let's say you need to change language later, the to makes little sense

I do the same and just construct the date sting however I want on the fly

1 like

Please or to participate in this conversation.