2011-07-18 22 views
0

sqliteの2つの日付の差を計算しようとしています。 私の時間は形式である:15h302つの日付の差sqlite

私はこれをしようとすると:

select time(replace(FIRSTHOUR , 'h' , ':'))-time(replace (SECONDHOUR , 'h' , ':')) 
from table 

私の日付は私が取得できますか15h3017h40

ある場合、私はちょうど2のような時間で結果を得ます2:10のような時と分の結果ですか?

答えて

1
sqlite> select strftime('%H:%M', 
         strftime('%s', replace('17h40', 'h' , ':')) 
         - strftime('%s', replace ('15h30', 'h' , ':')), 
         'unixepoch'); 
02:10 
sqlite> 

ので、代わりに

sqlite> select strftime('%H:%M', 
         strftime('%s', replace(FIRSTHOUR, 'h' , ':')) 
         - strftime('%s', replace (SECONDHOUR, 'h' , ':')), 
         'unixepoch'); 

、そう

sqlite> select strftime('%H:%M', 
         julianday(replace('17h40', 'h' , ':')) 
         - julianday(replace ('15h30', 'h' , ':')) 
         - 0.5); 
02:10 
sqlite> 

、それが動作

sqlite> select strftime('%H:%M', 
         julianday(replace(FIRSTHOUR, 'h' , ':')) 
         - julianday(replace (SECONDHOUR, 'h' , ':')) 
         - 0.5); 
+0

はあなたに感謝します! – jerem