trafodion日期运算——trafodion timestamp与unix timestamp互相转换

在应用开发中,我们经常需要把年月日时分秒格式数据转化为unix timestamp格式。

在trafodion中,没有直接的函数把年月日时分秒(例如:2017-07-16 15:58:32)格式的数据转化为unix timestamp,

但是我们可以使用其他函数来实现对应的功能。

1、trafodion timestamp转unix timestamp示例(trafodion类似mysql的UNIX_TIMESTAMP函数):

>>SELECT DATEDIFF( SECOND, TIMESTAMP '1970-01-01 00:00:00', TIMESTAMP '2017-07-16 15:58:32') FROM DUAL;
(EXPR)     
-----------
 1500220712
--- 1 row(s) selected.

或者

>>select timestamp'2017-07-16 15:58:32' - timestamp'1970-01-01 00:00:00' from dual;
(EXPR)       
-------------
   1500220712
--- 1 row(s) selected.

2、unix timestamp转trafodion timestamp示例(trafodion类似mysql的FROM_UNIXTIME函数):

>>select dateadd(SECOND,1500220712,timestamp '1970-01-01 00:00:00') from dual;

(EXPR)

---------------------

2017-07-16 15:58:32.0

--- 1 row(s) selected.



猜你喜欢

转载自blog.csdn.net/yangpengpeng2015/article/details/78980399
今日推荐