我正试图在postgres查询中自动考虑时区。我的目标是在EST或UTC - 5:00选择0:00到23:59之间的记录。
当前查询仅返回UTC时间0:00到23:59之间的记录。
select path, start_time from routes where routes.network_id = 1 and routes.start_time between '2017-06-13 00:00:00'::timestamp AND '2017-06-13 23:59:59'::timestamp
列start_time
是没有时区的时间戳,因此默认情况下它是UTC
SELECT pg_typeof("start_time") from routes limit 1;
返回timestamp without timezone
如何编写查询以解决5小时差异并将start_time
转换为UTC - 5?
答案 0 :(得分:2)
试试这个:
select path, start_time - interval '5 hours' as start_time_est
from routes
where routes.network_id = 1
and routes.start_time between '2017-06-13 00:00:00-5'::timestamp with time zone
AND '2017-06-13 23:59:59-5'::timestamp with time zone;