title: How to Get Min and Max DateTime from MongoDB using c# queries?
body: <p>I wrote query for Sorting and MAX and MIN Records of DateTime using MongoDB c# queries.
  i wrote as </p>
  
  <pre><code>var server = MongoServer.Create(this.connectionString);
  var db = server.GetDatabase(DATABASE);
  var tblRskAlerts = db.GetCollection(RISKALERT_TBL);
  var query = Query.And(Query.EQ("Entry", null));
  var sort = tblRskAlerts.Find(query).SetSortOrder(SortBy.Ascending("Entry"));
  var sort =SortBy.Ascending("Entry");
  var fromDt = sort.Max(x =&gt; x["Entry"].ToJson());
  var toDt = sort.Min(x =&gt; x["Entry"].ToJson());
  txtToCal.Text = ((DateTime)toDt).ToLocalTime();
  </code></pre>
  
  <p>Now i want to show fromDt,toDt into Textboxes.
  But I got error as Can not convert String into DateTime.</p>