Closed
Description
Hello,
first want to say that your extension is awesome!
I have one question... I have mongodb collection saved with models that have column type "Date". When I access that collection I see that column with Date type is actually MongoDate object.
My question is how I can query by that column? I have tried next scenarios with no success:
DB::connection('mongodb')->collection('names')->where('date', '<', new MongoDate())
DB::connection('mongodb')->collection('names')->where('date', '<', new DateTime())
DB::connection('mongodb')->collection('names')->where('date', '<', time())
DB::connection('mongodb')->collection('names')->where('date', '<', date('Y-m-d'))
Thanks,
Milos
Activity
jenssegers commentedon Oct 14, 2013
For me,
MongoDate()
seems to be working. Butnew DateTime
would be better I think.devbeans commentedon Nov 7, 2013
I am also having a problem with the dates, I have a script like this:
$from = new MongoDate(Input::get('from')); //from is in time format
$to = new MongoDate(Input::get('to')); // to is in time format
$between = array( $from, $to);
$leads = Lead::whereBetween('created_at', $between)->get();
I don't know what I'm missing but the date range is not working, is there something I am missing? Thanks for writing a great extension btw.
Cheers,
Albert
jenssegers commentedon Nov 7, 2013
I'm looking into this right now.
Adding date tests for issue #51
jenssegers commentedon Nov 7, 2013
I did not encounter any problems with dates. Check the date tests in 93e53ec
devbeans commentedon Nov 7, 2013
Awesome, got some tips from your tests. Thank you
Builder now converts DateTime objects to MongoDate, see issue #51
jenssegers commentedon Nov 7, 2013
Added some more date tweaks and a bit of documentation: https://github.com/jenssegers/Laravel-MongoDB#dates
jenssegers commentedon Nov 8, 2013
I added Carbon date support to the latest version. Can anyone report back if he's having problems with these changes?
sebastiaanluca commentedon Jan 23, 2014
Could you perhaps quickly explain how to get MongoDate objects converted to Carbon instances? Whenever I read out data, the
created_at
andupdated_at
fields are always of the MongoDate type.atapatel commentedon Oct 9, 2015
I am facing the issue with new version..
jkpatil211 commentedon Oct 27, 2015
@sebastiaanluca : u can use MongoDate::toDateTime as given in following link
http://php.net/manual/en/mongodate.todatetime.php
saraht129 commentedon Jan 29, 2016
@jenssegers The
whereBetween
query doesn't work with Carbon date, only MongoDate. Using v2.2.4.Is the Carbon date support not applicable to this case? Thanks!
thiagoalves-dev commentedon Aug 1, 2016
I am facing the issue with new version..²
mshahamirian commentedon May 22, 2017
@saraht129 @jenssegers I've tired your solution and still get empty result! Also tried (for example)
User::where('created_at','>',$startDate)->where('created_at','<',$endDate)->get();
still get empty result.
I don't know why it doesn't work with more than one where clause 😞
Adding date tests for issue mongodb#51
Builder now converts DateTime objects to MongoDate, see issue mongodb#51