PGSQL - 如何在WHERE子句中添加5个小时的日期?

时间:2017-04-06 15:36:41

标签: postgresql

我需要添加5小时或从GMT转换为EST。回报目前显示的是7p及以后的所有内容......

WHERE
incident.initial_symptom = 'Chrome Upgrade' AND
DATE(incident.install_completed) = CURRENT_DATE;

1 个答案:

答案 0 :(得分:2)

不是手动添加间隔以获得所需的时区,而是在时区使用,例如:

t=# select now(), now() at time zone 'est';
             now              |         timezone
------------------------------+---------------------------
 2017-04-07 07:07:39.17234+00 | 2017-04-07 02:07:39.17234
(1 row)

根据您的时区,与您的日期相同的语句添加间隔会产生不同的结果,例如在DST班次时间:

t=# set timezone TO 'WET';
SET
t=# select '2017-03-26 00:00:00'::timestamptz + '1 hour'::interval;
        ?column?
------------------------
 2017-03-26 02:00:00+01
(1 row)

t=# set timezone TO 'EET';
SET
t=# select '2017-03-26 00:00:00'::timestamptz + '1 hour'::interval;
        ?column?
------------------------
 2017-03-26 01:00:00+02
(1 row)