我想找到两个时间戳之间的日期。查询必须返回一个整数值。我有一个列值和一个固定日期(如 t.movementdate 和 '2014-07-23 00:00:00.0')。
问问题
146 次
2 回答
2
你可以试试这个
CREATE TABLE t (movementdate TIMESTAMP);
INSERT INTO t VALUES (TIMESTAMP '1014-07-21 03:23:02.0');
INSERT INTO t VALUES (TIMESTAMP '2014-07-22 10:54:02.0');
select actual_diff,extract (day from actual_diff)+
extract (hour from actual_diff)/24
+extract (minute from actual_diff)/(60*24)
+extract (second from actual_diff)/(60*60*24)
diff_in_days
from (select systimestamp- movementdate as actual_diff from t);
于 2014-07-23T09:00:15.250 回答
0
好问题。恕我直言,Oracle 的时间戳算法非常难看。如果您需要天数差异,可以将 转换TIMESTAMP
为DATE
. 根据您的需要,您还可以使用TRUNC
. 一旦你有了DATE
s,你可以简单地减去它们以获得天数的差异:
CREATE TABLE t (movementdate TIMESTAMP);
INSERT INTO t VALUES (TIMESTAMP '2014-07-21 03:23:02.0');
INSERT INTO t VALUES (TIMESTAMP '2014-07-22 10:54:02.0');
SELECT t.movementdate, DATE '2014-07-23' - trunc(t.movementdate) as daydiff FROM t;
MOVEMENTDATE DAYDIFF
---------------------------- ----
21.07.2014 03:23:02,000000000 2
22.07.2014 10:54:02,000000000 1
于 2014-07-23T08:24:05.567 回答