SQL 如何将日期和时间组合成 db2 中的时间戳?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15156502/
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 13:59:02  来源:igfitidea点击:

How to combine date and time into a timestamp in db2?

sqldatetimedb2timestamp

提问by xan

In a db2database I have a DATEcolumn and a TIMEcolumn, how can you combine these into a single TIMESTAMP?

db2数据库中,我有一个DATE列和一个TIME列,如何将它们组合成一个TIMESTAMP

回答by

The timestampfunctioncan be called with two arguments, one of which is date and one of which is time:

可以使用两个参数调用该timestamp函数,其中一个是日期,一个是时间:

select timestamp(date_col,time_col) from your_table

回答by xan

As per this thread, the [TIMESTAMP][2]function can accept 2 parameters, so you can simply pass it the DATEand TIMEcomponents and it constructs the TIMESTAMPfor you.

根据此线程,该[TIMESTAMP][2]函数可以接受 2 个参数,因此您只需将DATETIME组件传递给它,它就会TIMESTAMP为您构造。

SELECT MyDate, 
       MyTime, 
       TIMESTAMP(MyDate, MyTime) AS MyTimestamp 
FROM MyTable