title: Find mongodb objects using ISODate using JAVA
body: <p>The <a href="https://stackoverflow.com/questions/2943222/find-objects-between-two-dates-mongodb">Find objects between two dates MongoDB</a> is answering the mongoshell command. But I require it to do in Java. I have explained my question a bit more. hope this helps</p>
  
  <p>Below is the object</p>
  
  <pre><code> {
      "_id" : ObjectId("5a8f997fcdc2960adae4f91a"),
      "cobDate" : ISODate("2018-02-15T18:30:00.000Z"),
      "Version" : 1
  }
  </code></pre>
  
  <p>Query that worked in MongoShell </p>
  
  <pre><code>db.getCollection('collection').find({"cobDate" : { "$gt" : ISODate("2018-04-04T00:00:00.000Z"), "$lte" : ISODate("2018-04-06T00:00:00.000Z")}})
  </code></pre>
  
  <p>Below is my Java code.</p>
  
  <pre><code>        String businessDate = "2018-04-05"; //This is the argument to be passed in string by user
          LocalDate sDate = LocalDate.parse(businessDate);
          LocalDate eDate = sDate.plusDays(1);
          SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
          Date ssdate = format.parse(sDate.toString());
          Date eedate = format.parse(eDate.toString());
  
          String startDate = MongoConnect.toISO8601UTC(ssdate);
          String endDate = MongoConnect.toISO8601UTC(eedate);
  
          BasicDBObject query = new BasicDBObject();
          query.put("cobDate", BasicDBObjectBuilder.start("$gt", endDate).add("$lte", endDate).get()) ; 
  
          db.getCollection(collectionName).find(query)
  </code></pre>
  
  <p>here syso(query) output is-->     </p>
  
  <pre><code>{"cobDate" : { "$gt" : "2018-04-04T00:00:00.000Z", "$lte" : "2018-04-06T00:00:00.000Z" } } 
  </code></pre>
  
  <p>and does not work for me where "cobDate" stored like <strong>ISODate("2018-04-05T00:00:00.000Z"</strong></p>