try this:
$current_date=date('Y-m-d');
$maintenance=Maintenance::where('admin_id', $admin_id)->whereBetween($current_date, ['due_from', 'due_to'])->get()->toArray();
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
my code is
$current_date=date('Y-m-d');
$maintenance=Maintenance::get()->where('admin_id', '=', $admin_id)->whereBetween($current_date, ['due_from', 'due_to'])->toArray();
but i get an empty array value
any body know how to fetch this
$current_date=date('Y-m-d'); // '2020-03-23'
$maintenance=Maintenance::where('admin_id',$admin_id) // we know this returns results
//so filter...
->where('due_from', '<', $current_date) // where $current_date is after due_from
->where('due_to', '>', $current_date) // AND where $current_date is before due_to
->get()->toArray();
However, if you want to include the date e.g. if today was 2020-03-01 and the due_from was 2020-03-01 and should still show up, do this instead:
$maintenance=Maintenance::where('admin_id',$admin_id) // we know this returns results
//so filter...
->where('due_from', '<=', $current_date) // where $current_date is after or the same as due_from
->where('due_to', '>=', $current_date) // AND where $current_date is before or the same as due_to
->get()->toArray();
Please or to participate in this conversation.