Hank
Hank

Reputation: 3497

Django query using mysql date functions

I was wondering can you perform the following query in Django using models and queryset?

SELECT count(*), DATE_FORMAT(FROM_UNIXTIME(created_at/1000), '%Y-%m-%d') FROM users
GROUP BY YEAR(FROM_UNIXTIME(created_at/1000)), MONTH(FROM_UNIXTIME(created_at/1000)), 
DAY(FROM_UNIXTIME(created_at/1000))
ORDER BY created_at ASC;

Upvotes: 0

Views: 369

Answers (1)

Martin B.
Martin B.

Reputation: 1926

Not really no.. see https://docs.djangoproject.com/en/1.6/ref/models/querysets/#field-lookups - would just use a raw SQL query

Upvotes: 1

Related Questions