title: pymongo query by datetime
body: <p>I got one problem which made me headache for almost one day.</p>
  
  <p>The python scripts are:</p>
  
  <pre><code># coding:utf-8
  import pymongo
  import datetime, time
  
  def query_data(IP,datefrom,dateto):
      conn = pymongo.MongoClient(IP)
      db = conn.mymongo
  
      startdate = time.mktime(time.strptime(datefrom,'%Y-%m-%d'))
      enddate = time.mktime(time.strptime(dateto,'%Y-%m-%d'))
  
      # all above are correct definitely.
      #
      # but I got no result from this line below.
      cursor = db.find({'username':'test','created':{'$gte':startdate,'$lt':enddate}})
      print cursor.count()
      # with above code, I got 0 returned though I can see it is nonzero in database.
      # 
      # If I use this below with single datetime, I can see result. But it is not my intention.
      # cursor = db.find({'username':'test','created':datefrom})
      # print cursor.count()
  
      tempData = []
      for doc in cursor:
          print doc['twitter']
          tempData.append(doc['twitter'])
  
      print len(tempData)
      return tempData
  
  result = query_data('192.168.100.20','2014-4-1','2014-5-1')
  </code></pre>
  
  <p>The question is what was wrong with my code above?
  Or how can I query data from mongoDB between two dates, with pymongo script?</p>