0

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.

3 Answers 3

1
 DB::table('table_name')->whereBetween('started_at', [$date1, $date2])
  ->orWhereBetween('finished_at', [$date1, $date2])->get();
Sign up to request clarification or add additional context in comments.

Comments

0
$date = date('Y-m-d',strtotime($started_at));


$data = Model::where('started_at', '>', $date)->where('finished_at', '<', $date)->first();

Comments

0

Try this

$data = Model::where('started_at', '<', $date)->where('finished_at', '>', $date)->first();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.