title: On searching documents in mongodb collection using ISODate range, I get the error "String was not recognized as a valid DateTime"
body: <p>I am trying to query MongoDB using the following -</p>
  
  <pre><code>List&lt;BsonDocument&gt; list = NoSqlBusinessEntityBase.LoadByWhereClause("peoplecounting",
      string.Concat("{siteid:\"", siteid, "\", locationid:\"", location._id ,"\",
      StartTime: {$gte:ISODate(\"",old.ToString("yyyy-mm-dd hh:mm:ss"),"\")}, 
      EndTime: {$lte:ISODate(\"",current.ToString("yyyy-MM-dd hh:mm:ss"), "\"\")}}"));
  </code></pre>
  
  <p>The LoadByWhereClause() function is as follows -</p>
  
  <pre><code>public static List&lt;BsonDocument&gt; LoadDataByWhere(string table, string whereClause)
  {
      var collection = db.GetCollection(table);
      QueryDocument whereDoc = new QueryDocument(BsonDocument.Parse(whereClause));
      var resultSet = collection.Find(whereDoc);
      List&lt;BsonDocument&gt; docs = resultSet.ToList();
  
      if (resultSet.Count() &gt; 0)
      {
          foreach (BsonDocument doc in docs)
          {
              doc.Set("_id", doc.GetElement("_id").ToString().Split('=')[1]);
          }
          return docs;
      }
      else
      {
          return null;
      }
  }
  </code></pre>
  
  <p>Even though the query runs fine in MongoDB console and returns documents</p>
  
  <pre><code>db.peoplecounting.find({siteid:"53f62abf66455068373665ff", locationid:"53f62bb86645506837366603",
      StartTime:{$gte:ISODate("2012-12-03 02:40:00")}, EndTime:{$lte:ISODate("2013-12-03 07:40:00")}}
  </code></pre>
  
  <p>I get the error when I try to load in C# using the LoadByWhereClause function. The error is <code>String was not recognized as a valid DateTime.</code> while parsing the whereClause.
  How can I possibly fix this? I am unable to determine what is going wrong here.</p>