title: MongoDB Raw query to select documents which are in given datetime period
body: <p>I want to select documents which are in user given date time period like between : </p>
  
  <pre><code>$from_date : "2017-01-07 09:08:59" To `$to_date : "2017-08-09 09:08:59"` 
  </code></pre>
  
  <p>I'm using laravel framework and jenssegers/laravel-mongodb mongodb driver to run my query, And this is my Raw query :</p>
  
  <pre><code> $normal_banners = BannerView::raw(function ($collection) use ($id, $from_date, $to_date) {
        $conditions = [
           ["camp_id" =&gt; ['$eq' =&gt; $id]],
           ['$or' =&gt; [
                ['seat_target_status' =&gt; ['$eq' =&gt; true]],
                ['seat_target_status' =&gt; ['$eq' =&gt; false]]
           ]],
           ['camp_target_status' =&gt; ['$eq' =&gt; false]],
           ];
  
           if ($from_date) {
              $conditions[] = ['created_at' =&gt; ['$gte' =&gt; $from_date]];
           }
  
           return $collection-&gt;aggregate([
              ['$match' =&gt; ['$and' =&gt; $conditions]],
           ]);
      })-&gt;count();
  </code></pre>
  
  <p>But my problem is that it returns 0 as result; while there are 16 documents in this time period. </p>
  
  <p>I've tried this method to get the count of them but still 0 result :</p>
  
  <pre><code>   $normal_banners = BannerView::Where('camp_id', $id)
          -&gt;where(function ($query) {$query-&gt;where('seat_target_status', true)-&gt;orWhere('seat_target_status', false);
             })
          -&gt;where('camp_target_status', false)
          -&gt;where("created_at", "&gt;=", $from_date)
          -&gt;count();
  </code></pre>
  
  <p>FYI : I've converted datetime of input to ISODate Which is the mongodb datatype for <code>created_at</code> field. </p>
  
  <pre><code>$Fromdatetime = $request-&gt;input('from_date');
  $from_date = new DateTime($Fromdatetime);
  $from_date = $from_date-&gt;format(DateTime::ISO8601);
  </code></pre>
  
  <p>mongodb field data type is : </p>
  
  <pre><code> "updated_at": ISODate("2017-04-10T09:35:58.641Z"),
     "created_at": ISODate("2017-04-10T09:35:58.641Z")
  </code></pre>
  
  <p>My input data type is : <code>"2017-01-07T09:08:59+0000"</code></p>
  
  <p>Any suggestion ?</p>