Reputation: 195
I am using an eloquent query to retrieve data from a table. The table columns look like this:
id started_at finished_at
1 06/02/2019 06/15/2019
2 06/05/2019 06/11/2019
What I want to do is, given a $date
(ex: 06/08/2019 ) and get the data of the row, that the $date between started at and finished_at columns.
Upvotes: 0
Views: 56
Reputation: 2610
Try this
$data = Model::where('started_at', '<', $date)->where('finished_at', '>', $date)->first();
Upvotes: 0
Reputation: 1156
$date = date('Y-m-d',strtotime($started_at));
$data = Model::where('started_at', '>', $date)->where('finished_at', '<', $date)->first();
Upvotes: 0
Reputation: 61
DB::table('table_name')->whereBetween('started_at', [$date1, $date2])
->orWhereBetween('finished_at', [$date1, $date2])->get();
Upvotes: 1