2017-07-07 54 views
0

在我試圖自動帳戶在我的postgres查詢時區。我的目標是選擇在美國東部時間或UTC - 5:00之間0:00到23:59之間的記錄。會計在Postgres查詢時區

當前查詢僅在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

這是Postgres的 –

回答

1

試試這個:

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;