title: Mongo date range query using _id in PHP
body: <p>Being relatively new to mongo, I read in the mongo manual about Optimizing Object IDs.</p>
  
  <p><a href="http://www.mongodb.org/display/DOCS/Optimizing+Object+IDs#OptimizingObjectIDs-Extractinsertiontimesfromidratherthanhavingaseparatetimestampfield">http://www.mongodb.org/display/DOCS/Optimizing+Object+IDs#OptimizingObjectIDs-Extractinsertiontimesfromidratherthanhavingaseparatetimestampfield</a>.</p>
  
  <p>Going with the recommendation about NOT creating a separate Created_On field, I decided I would later extract out the date from the <code>_id</code> field which is an <code>ObjectID</code></p>
  
  <p>Now, I have many records all with out a Created_On field.</p>
  
  <p>I am attempting to query for a date range, but am unsure of the syntax:</p>
  
  <pre><code>$start = new MongoDate(strtotime("2012-03-01 00:00:00"));
  $end = new MongoDate(strtotime("2012-03-15 00:00:00"));
  
  $collection-&gt;find(array('_id' =&gt; array('$gt' =&gt; $start, '$lte' =&gt; $end)));
  </code></pre>
  
  <p>Always returns 0 results. Although I can query individual records and extract the date from the object.</p>