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

tesarwijaya's avatar

Eloquent whereDate query give different than expected result

I have query where i need to select using whereDate function, here is my query.

$histories = History::where('location_id', 71)->whereDate('started_at', date('Y-m-d', strtotime('2017-07-27')))->get();

and DB query log:

Array
(
    [0] => Array
        (
            [query] => select * from `history` where `location_id` = ? and date(`started_at`) = ?
            [bindings] => Array
                (
                    [0] => 71
                    [1] => 2017-07-27
                )

            [time] => 1.87
        )

)

i guess there's nothing wrong with query, because it's turn out like what i expect. but, then i copy its query from query log to database administrator apps with same value it's resulting 19 rows, laravel eloquent only resulting 7 rows. why it can give different result?

please help me, is there any bug on where date function? because i tried to change it using DB facedes version but its result is same as eloquent

if it can be some help, this is my history table structure

id (int), location_id (int), started_at(datetime), ended_at(datetime)

0 likes
1 reply
khizer1030's avatar

try this

$q->whereDate('created_at', '=', date('Y-m-d'));

Please or to participate in this conversation.