Django model filter compare month fail <p>Suppose I have this model:</p> <pre><code>class User(models.Model): id = models.AutoField(primary_key=True) username = models.CharField(max_length=10) last_login = models.DateTimeField(null=True) </code></pre> <p>Here is one of the records in database,</p> <pre><code>id=15, username='yhbohh' last_login='2015-03-31 10:57:18' </code></pre> <p>I would like to get a number count of objects with last login of month=3.</p> <p>I tried in shell,</p> <pre><code>User.objects.filter(last_login__year=2015).count() # return 80 User.objects.filter(last_login__month=3).count() # return 0 User.objects.filter(last_login__day=31).count() # return 0 </code></pre> <p>May I know why the last 2 queries return no records? I have searched from the other questions and notice than someone may suggest to use date range comparison to solve this problem. But I just wanna know the root cause of this unexpected result.</p> <p>Thanks a lot!</p>