2013-10-18 199 views
-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 
+0

爲什麼Java標記這裏? – SpringLearner

+0

我想在java中做到這一點。所以如果有一些Java特定的粗糙方式來實現這一點。 – Andy897

+0

你到底需要做什麼?你試圖完成什麼? –

回答

3

首先,如果你真的想從數據庫中毫秒的細節,你需要檢查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 
+0

很大的幫助!!!!而且非常翔實......感謝Bud。只是一個快速Q.什麼9代表「第二(9)」 – Andy897

+0

@ Andy897所以你的問題是沒有針對Java的畢竟= \ –

+1

當使用間隔時,你需要指定的「範圍」較大的值,爲例如,您可以將此值放入間隔日期類型:「10432.455」,意思是10,432秒。 (9)意味着你可以使用9位數字〜= 999,999,999秒,如果你限制爲(3),那麼你可以將數值限制爲999秒....... plus:這可以很容易地轉換爲日期':間隔日(3)至第二'。 – ceinmart

-3

對不起,特定於Java代碼,但下面是SQL代碼,可以是有用的U:

select (datediff(ss,StartDate,EndDate)*1000) 
+0

....我不確定Informix有'datediff()'函數。請注意,DB2版本返回的估計值通常毫無價值。 –

+0

這個函數在informix中不存在(當前版本,12.10) – ceinmart

相關問題