首页 > 解决方案 > 添加时间戳在红移中不起作用

问题描述

select CAST(current_date as timestamp) 
         + to_char(timestamp '2019-07-08 09:00:00','YYYY-MM-DD HH24:MI:SS')::TIMESTAMP;

电流输出: 2019-08-02 00:00:002019-07-08 09:00:00

标签: amazon-redshift

解决方案


您可以使用DATEADD()函数或INTERVAL语法将特定的时间单位添加到另一个日期/时间戳。

SELECT DATEADD(hour, 9, current_date);
--       date_add
-- ---------------------
--  2019-08-05 09:00:00

SELECT current_date + INTERVAL '9 hours';
--       ?column?
-- ---------------------
--  2019-08-05 09:00:00

推荐阅读