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

knubbe82's avatar

Find entity where given date is between entity start and end

I have entity Authorization with start and end attributes. How to find specific authorization with given date that is between start and end but last authorization don't need to have end (it's not required). In that case I need between start and now. How to do that?

0 likes
2 replies
Wraith's avatar

maybe whereBetween('data_field', [$from, $to])->get(); $from, $to is like date('yyy-mm-dd')

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Something like this

Auth::where('start', '>=', $start)->where(function ($q) {
$q->where('end', '<', $end)->orWhereNull('end');
})->get();

Please or to participate in this conversation.