Laravel-mongodb: Issues with date whereBetween not work

Created on 29 Aug 2017  路  4Comments  路  Source: jenssegers/laravel-mongodb

my code:
$startDate = new \DateTime($startDate);
$endDate = new \DateTime($endDate);
User::whereBetween('created_at', [$startDate, $endDate ]);

Execute SQL:
User.aggregate([{"$match":{{"created_at":{"$gte":{"date":"2016-09-01 00:00:00.000000","timezone_type":3,"timezone":"Asia\/Shanghai"},"$lte":{"date":"2017-09-01 00:00:00.000000","timezone_type":3,"timezone":"Asia\/Shanghai"}}},{"deleted_at":null}]}},{"$group":{"aggregate":{"$sum":1},"_id":null}}],{"typeMap":{"root":"array","document":"array"}})

Please help

bug fixed

Most helpful comment

I have the same issue.
To fix this I use

where($dateField,'>=',$begin)->where($dateField,'<=',$end)

and works great!

All 4 comments

I also had this problem

I have the same issue.
To fix this I use

where($dateField,'>=',$begin)->where($dateField,'<=',$end)

and works great!

@Wu4m4n me too

I have the same issue.
To fix this I use

where($dateField,'>=',$begin)->where($dateField,'<=',$end)

and works great!

i have tried all this earlier, it doesnt work with time, only the date is considered in the quey, i need it to filter date and time

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pirmax picture pirmax  路  3Comments

Idnan picture Idnan  路  3Comments

phuocduy1988 picture phuocduy1988  路  3Comments

geofflancaster picture geofflancaster  路  3Comments

naveedyasin picture naveedyasin  路  3Comments