Ugly, but it works
DB::query()
->from('users')
->whereBetween(\DB::raw('DATE(date)'), [$startDate, $endDate])
->get();
Or on an Eloquent model:
User::whereBetween(DB::raw('DATE(date)'), [$startDate, $endDate])->get();
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, I'm playing with the whereBetween - query for 2 dates.
Given is a date 2018-10-04 01:02:03
So the whereBetween should ignore the hours and seconds, is that possible?
$query->whereBetween('date', [$startDate, $endDate]);
with
$startDate = 2018-01-01;
and
$endDate = 2018-10-05;
works fine, if I set day in the $endDate to 04. it's not returning anything (for sure not).
Thank you.
if you set the end date to the end of the 4th or the start of the 5th then the hours and minutes become irrelevant
You dont show how you get the end date, but I would use this approach then you can use the standard eloquent whereBetween
Please or to participate in this conversation.