Coder Social home page Coder Social logo

Comments (13)

saraht129 avatar saraht129 commented on June 12, 2024 1

@jenssegers The whereBetween query doesn't work with Carbon date, only MongoDate. Using v2.2.4.

    $startDate = Carbon::createFromDate(2015, 4, 1);
    $endDate = Carbon::createFromDate(2015, 4, 30);
    $users = User::whereBetween('created_at', array($startDate, $endDate))->get();
    //Return empty result

    $startDate = new MongoDate(Carbon::createFromDate(2015, 4, 1)->timestamp);
    $endDate = new MongoDate(Carbon::createFromDate(2015, 4, 30)->timestamp);
    $users = User::whereBetween('created_at', array($startDate, $endDate))->get();
    //Return correct results

Is the Carbon date support not applicable to this case? Thanks!

from laravel-mongodb.

thiagoalves-dev avatar thiagoalves-dev commented on June 12, 2024 1

I am facing the issue with new version..²

from laravel-mongodb.

jenssegers avatar jenssegers commented on June 12, 2024

For me, MongoDate() seems to be working. But new DateTime would be better I think.

from laravel-mongodb.

devbeans avatar devbeans commented on June 12, 2024

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

from laravel-mongodb.

jenssegers avatar jenssegers commented on June 12, 2024

I'm looking into this right now.

from laravel-mongodb.

jenssegers avatar jenssegers commented on June 12, 2024

I did not encounter any problems with dates. Check the date tests in 93e53ec

from laravel-mongodb.

devbeans avatar devbeans commented on June 12, 2024

Awesome, got some tips from your tests. Thank you

from laravel-mongodb.

jenssegers avatar jenssegers commented on June 12, 2024

Added some more date tweaks and a bit of documentation: https://github.com/jenssegers/Laravel-MongoDB#dates

from laravel-mongodb.

jenssegers avatar jenssegers commented on June 12, 2024

I added Carbon date support to the latest version. Can anyone report back if he's having problems with these changes?

from laravel-mongodb.

sebastiaanluca avatar sebastiaanluca commented on June 12, 2024

Could you perhaps quickly explain how to get MongoDate objects converted to Carbon instances? Whenever I read out data, the created_at and updated_at fields are always of the MongoDate type.

from laravel-mongodb.

atapatel avatar atapatel commented on June 12, 2024

I am facing the issue with new version..

from laravel-mongodb.

jkpatil211 avatar jkpatil211 commented on June 12, 2024

@sebastiaanluca : u can use MongoDate::toDateTime as given in following link
http://php.net/manual/en/mongodate.todatetime.php

from laravel-mongodb.

mshahamirian avatar mshahamirian commented on June 12, 2024

@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 😞

from laravel-mongodb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.