我可以找到類似的內容,以秒爲單位找出差異。但我無法找到如何以毫秒爲單位找到差異。以毫秒爲單位的兩個日期時間之間的差異(Informix)
select (start_time - datetime(2013-08-12 19:05:34.223) year to fraction(3))
::interval second(9) to second
from table1 where event_id = 1
我可以找到類似的內容,以秒爲單位找出差異。但我無法找到如何以毫秒爲單位找到差異。以毫秒爲單位的兩個日期時間之間的差異(Informix)
select (start_time - datetime(2013-08-12 19:05:34.223) year to fraction(3))
::interval second(9) to second
from table1 where event_id = 1
首先,如果你真的想從數據庫中毫秒的細節,你需要檢查USEOSTIME參數被激活(默認不是)。
Informix僅將數據庫配置爲使用OS TIME(這意味着它們使用OS gettime()函數)時顯示小數/毫秒。
當該選項被禁用時,小數部分總是爲零。
如果未激活,您或DBA需要在onconfig文件中更改此設置並重新啓動引擎。
只要小心,因爲這會影響數據庫中使用的所有時間戳。
select * from sysmaster:sysconfig where cf_name = 'USEOSTIME';
cf_id 54
cf_name USEOSTIME
cf_flags 0
cf_original 1
cf_effective 1
cf_default 0
1 row(s) retrieved.
drop table if exists tp01;
Table dropped.
create temp table tp01 (dt datetime year to fraction);
Temporary table created.
insert into tp01 values (current);
1 row(s) inserted.
select * from tp01;
dt
2013-10-18 08:29:36.864
1 row(s) retrieved.
select dt, current, (current - dt)::interval second(9) to fraction from tp01;
dt (expression) (expression)
2013-10-18 08:29:36.864 2013-10-18 08:29:36.864 0.000
1 row(s) retrieved.
select dt, current, ((current - dt)::interval second(9) to fraction)*1000 from tp01;
dt (expression) (expression)
2013-10-18 08:29:36.864 2013-10-18 08:29:36.865 1.000
1 row(s) retrieved.
這裏,後等待8秒並且我重新運行上面的選擇...
dt (expression) (expression)
2013-10-18 08:30:44.539 2013-10-18 08:30:53.058 8.519
dt (expression) (expression)
2013-10-18 08:30:44.539 2013-10-18 08:30:53.058 8519.000
對不起,特定於Java代碼,但下面是SQL代碼,可以是有用的U:
select (datediff(ss,StartDate,EndDate)*1000)
....我不確定Informix有'datediff()'函數。請注意,DB2版本返回的估計值通常毫無價值。 –
這個函數在informix中不存在(當前版本,12.10) – ceinmart
爲什麼Java標記這裏? – SpringLearner
我想在java中做到這一點。所以如果有一些Java特定的粗糙方式來實現這一點。 – Andy897
你到底需要做什麼?你試圖完成什麼? –