title: Spring MongoDB - Finding Documents between two dates
body: <p>I am somewhat new to Java and am trying to write a query which will return the documents stored in my mongodb between two dates. I think I am close to getting it correct but am having a hard time getting there. I am receiving the date ranges in the following format:</p>
  
  <ul>
  <li>[2017-06-29, 2017-07-05]</li>
  </ul>
  
  <p>The dates that i am comparing are stored in the database as follows:</p>
  
  <ul>
  <li>yyyy-MM-dd'T'HH:mm:ss-SSSS</li>
  </ul>
  
  <p>What i have so far..</p>
  
  <pre><code>public List&lt;VehicleStatus&gt; getReportingDateRange(List&lt;String&gt; dates)  {
  
      DateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd");
      DateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss-SSSS");  
  
      Date startDate = outputFormat.parse(dates.get(0));      
      Date endDate = outputFormat.parse(dates.get(1));
  
      Query query = new Query();
  
      Criteria c = new Criteria().andOperator(Criteria.where("updateTime").gte(outputFormat.format(startDate)),  
              Criteria.where("updateTime").lte(outputFormat.format(endDate)));
  
      query.addCriteria(c);
  
      return this.mongoOperations.find(query, VehicleStatus.class);
  
     }
  </code></pre>
  
  <p>I am receiving a parse Exception. I am really not sure where to go from here, any help is greatly appreciated. If you need any additional information please let me know.</p>
  
  <p>Thank you!</p>