gpt4 book ai didi

postgresql - PGSQL - 如何在 WHERE 子句中向 DATE 添加 5 小时?

转载 作者:行者123 更新时间:2023-11-29 14:36:45 24 4
gpt4 key购买 nike

我要么需要增加 5 个小时,要么需要从 GMT 转换为 EST。返回当前显示从晚上 7 点到昨天晚些时候的所有内容...

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

最佳答案

与其手动添加时间间隔来获取想要的时区,不如使用 at time zone,例如:

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)

关于postgresql - PGSQL - 如何在 WHERE 子句中向 DATE 添加 5 小时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43259697/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com