2011-07-18 122 views
0

我试图计算sqlite中两个日期之间的差异。 我的时间是在格式为:15h30两个日期之间的区别sqlite

当我试试这个:

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

我刚刚得到的结果小时像2如果我的日期是15h3017h40

我怎样才能得到导致像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