SQL 将日期添加到时间戳

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6142916/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 10:46:50  来源:igfitidea点击:

Add Day to Timestamp

sqloracletimestampdate-arithmetic

提问by Nadir

How do I add days to a timestamp? If my timestamp is 01-JAN-2011 11-09-05and I add 2 days, I want 03-JAN-2011 11-09-05.

如何在时间戳中添加天数?如果我的时间戳是01-JAN-2011 11-09-05并且我添加了 2 天,我想要03-JAN-2011 11-09-05.

回答by Marc B

select '01-jan-2011 11-09-05' + interval '2' day

回答by DCookie

A completely Oracle-centric solution is to simply add 2 to the timestamp value as the default interval is days for Oracle dates/timestamps:

一个完全以 Oracle 为中心的解决方案是简单地将 2 添加到时间戳值,因为 Oracle 日期/时间戳的默认间隔是天:

SELECT TO_TIMESTAMP('01-jan-2011 11-09-05','DD-Mon-YYYY HH24-MI-SS') + 2
  FROM dual;