title: Basic between dates queries $gte, $lte, etc
body: <p>I'm having an issue with correct time formatting for my mongo query.</p>
  <p>My questions are these:</p>
  <ul>
  <li>Is <code>time.Time</code> the right go type for mongo ISODate object?</li>
  <li>Why is my time parsing seeming to parse a completely different date?</li>
  </ul>
  <p>Here's a complete example of what i've got going.</p>
  <pre><code>package main
  
  import (
      // &quot;fmt&quot;
      &quot;context&quot;
      &quot;log&quot;
      &quot;time&quot;
  
      &quot;go.mongodb.org/mongo-driver/bson&quot;
      &quot;go.mongodb.org/mongo-driver/mongo&quot;
      &quot;go.mongodb.org/mongo-driver/mongo/options&quot;
  )
  
  // Here's a JSON of the record as it is in the db
  // { 
  //  &quot;_id&quot; : ObjectId(&quot;5fa467af036d5f46914c423c&quot;), 
  //  &quot;subscriptionRuleId&quot; : &quot;email@email&quot;, 
  //  &quot;eventDateTime&quot; : ISODate(&quot;2020-11-05T20:59:27.096+0000&quot;), 
  //  &quot;eventType&quot; : &quot;string-with-event-type&quot;, 
  //  &quot;passportAtlas&quot; : &quot;a long string&quot;, 
  //  &quot;_class&quot; : &quot;com.proj.info.model.dto.EventLog&quot;
  // }
  
  type eventLog struct {
      SubscriptionRuleID string `json:&quot;subscriptionRuleId,omitempty&quot; bson:&quot;subscriptionRuleId&quot;`
      EventType string `json:&quot;eventType&quot; bson:&quot;eventType&quot;`
      EventDateTime time.Time `json:&quot;eventDateTime&quot; bson:&quot;eventDateTime&quot;`
      PassportAtlas string `json:&quot;passportAtlas&quot; bson:&quot;passportAtlas`
  }
  
  func main() {
      clientOptions := options.Client().ApplyURI(&quot;mongodb://localhost:27017&quot;)
      ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
      defer cancel()
  
      client, err := mongo.Connect(ctx, clientOptions)
  
      if err != nil { log.Fatal(err) }
  
      err = client.Ping(ctx, nil)
  
      if err != nil { log.Fatal(err) }
  
      collection := client.Database(&quot;compose&quot;).Collection(&quot;eventLog&quot;)
  
      df := &quot;2006-02-04&quot;
      dateFrom, _ := time.Parse(df, &quot;2020-11-20&quot;)
      dateTo, _ := time.Parse(df, &quot;2020-11-21&quot;)
  
      // This does not seem to work. 
      // A log of the dates gives me the wrong dates
  
      log.Printf(&quot;\nFROM: %v\nTO: %v&quot;, dateFrom, dateTo)
      // OUTPUTS:
      // FROM: 2020-01-09 00:20:00 +0000 UTC
      // TO: 2020-01-10 00:21:00 +0000 UTC
  
      // Notice the dates are formatted wrong in the log.
      // Even though the dates are wrong, I would still match
      // Records with those wrong dates as i've got tens of thousands
      // over the last few years...
   
      query := bson.M{
          &quot;eventDateTime&quot;: bson.M{
              &quot;$gte&quot;: dateFrom,
              &quot;$lt&quot;: dateTo,
          },
      }
  
      cur, err := collection.Find(ctx, query)
  
      if err != nil { log.Fatal(err) }
  
      defer cur.Close(context.Background())
  
      var eventLogs []eventLog
  
      for cur.Next(ctx) {
          var eventLog eventLog
          cur.Decode(&amp;eventLog)
          eventLogs = append(eventLogs, eventLog)
      }
  
      if err := cur.Err(); err != nil { log.Fatal(err) }
  
      log.Printf(&quot;num records: %v&quot;, len(eventLogs))
  }
  </code></pre>