[Fixed]-Django group by date with strftime in PostgreSQL

1👍

First of all, you get this error because you use double quotes instead of single quotes (I mean that you need to write '%%H', not "%%H"). But after that you’ll definitely get another error:

function strftime(unknown, timestamp with time zone) does not exist

So if you want to fix it, you can use date_trunc function instead of strftime.

UPDATE:

Since Django 1.10 you can use class Trunc with annotate instead of extra (this method is marked as deprecated), and it doesn’t depend on database that you use.

Leave a comment