title: Django count group by date from datetime
body: <p>I'm trying to count the dates users register from a DateTime field. In the database this is stored as '2016-10-31 20:49:38' but I'm only interested in the date '2016-10-31'.</p>
  
  <p>The raw SQL query is:</p>
  
  <pre><code>select DATE(registered_at) registered_date,count(registered_at) from User 
  where course='Course 1' group by registered_date;
  </code></pre>
  
  <p>It is possible using 'extra' but I've read this is deprecated and should not be done. It works like this though:</p>
  
  <pre><code>User.objects.all()
      .filter(course='Course 1')
      .extra(select={'registered_date': "DATE(registered_at)"})
      .values('registered_date')
      .annotate(**{'total': Count('registered_at')})
  </code></pre>
  
  <p>Is it possible to do without using extra?</p>
  
  <p>I read that TruncDate can be used and I think this is the correct queryset however it does not work:</p>
  
  <pre><code>User.objects.all()
      .filter(course='Course 1')
      .annotate(registered_date=TruncDate('registered_at'))
      .values('registered_date')
      .annotate(**{'total': Count('registered_at')})
  </code></pre>
  
  <p>I get <code>&lt;QuerySet [{'total': 508346, 'registered_date': None}]&gt;</code> so there is something going wrong with TruncDate.</p>
  
  <p>If anyone understands this better than me and can point me in the right direction that would be much appreciated.</p>
  
  <p>Thanks for your help.</p>