title: How to convert date format in mongodb
body: <p>I am using an API (so I have no control over the fields) - one of the fields is of type <code>Date</code>.  </p>
  
  <p>Now, I find that the date stored in the records resembles the following value:</p>
  
  <pre><code>{
      ...
      "foobarDate": "2013-05-26T05:00:00.000Z",
      ...
  }
  </code></pre>
  
  <p>Now I wish to retrieve some records based on this date - for example, I need to retrieve all the records whose <code>fooBarDate</code> is earlier than today's date.</p>
  
  <p>If I use Javascript's <code>Date()</code> functionality, then I get the date in the following format:<br>
  <code>Wed Jun 19 2013 21:13:50 GMT+0530 (IST)</code></p>
  
  <p>If I try to design my query as follows...</p>
  
  <pre><code>{
      "fooBarDate": {
          "$lte": &lt;the date calculated in javascript&gt;
      }
  }
  </code></pre>
  
  <p>...I do not get the records - I get an empty array - I suspect it is due the reason that the format of the Date stored in MongoDB is different from the one I am passing.</p>
  
  <p>How to convert the Javascript date format to the mongodb format? Or at least, how do I get the current date in the format stored in MongoDB?</p>
  
  <p>P.S. I am using nodeJs and wish to query the DB in this case.</p>