I am using the following queryset filter →
queryset.filter(created_at__date__gte=start_date, created_at__date__lte=end_date)
and it generates the SQL as →
("tce"."created_at")::date >= 2023-11-29 AND ("tce"."created_at")::date <= 2023-11-20
What I need is to incorporate timezone into it such that the SQL generated would be like →
("tce"."created_at" AT TIME ZONE 'Canada/Eastern')::date >= '2023-11-28' AND ("tce"."created_at" AT TIME ZONE 'Canada/Eastern')::date <= '2023-11-28'
Can someone assist me on how can this be achieved using the inbuilt ORM?
Can someone please help with this?
There are many possibilities here, and there’s not enough information to determine which case it is.
If the start_date
and end_date
being submitted are user entries from a form, or are from some other type of “date-only” field, then what I think you really want to do is convert those submitted dates to datetime objects for the appropriate timezone, and use those converted values in the comparison. (This is what we do.) This is going to be a much faster operation on the database than requiring it to cast two fields in every row to perform the comparison.