[Django]-Django raw sql with datetime

5👍

This is show your how python and psql interpret datetime’s strings tzinfo.

psql using your string time as UTC.
python send it to db with +hours_of_your_time_zone

If your tz +07 so try in python:

with connection.cursor() as cursor:

    cursor.execute(
        "SELECT * from orders_orderstatus WHERE datetime > '2017-09-05 09:07:16'"
    )
    row = [item[0] for item in cursor.fetchall()]
return row

In future try to use datetime objects with tz.

Looks like you have setting:

USE_TZ=True

Leave a comment