Oracle日期减法 [英] Oracle Date Subtraction
问题描述
我该如何写一个表达式,使我以天,小时,分钟,秒等为单位的两个日期之间的差值?默认情况下,在oracle中减去两个日期将以天为单位返回天.
How would i write an expression that gives me the difference between two dates in days, hours, minutes, seconds, etc? By default subtracting two dates in oracle returns days as a decmial.
推荐答案
该十进制表示所提供的两个日期之间的天数差.您可以做一些数学运算,将其转换为天,小时,分钟,秒等.
That decimal is the number of days difference between the two dates provided. You can do a little math to convert that to days, hours, minutes, seconds, etc.
编辑:我明白了您要查找的内容.我敢肯定有一种更简单的方法,但是我可能会这样完成:
EDIT: I see what you're looking for. I'm sure there's an easier way, but I would probably accomplish it thusly:
select trunc(5.3574585) days,
trunc(mod((5.3574585) * 24, 24)) hours,
trunc(mod((5.3574585) * 24 * 60, 60)) minutes,
trunc(mod((5.3574585) * 24 * 60 * 60, 60)) seconds
from dual;
...其中5.3574585是减法返回的天数...
...where 5.3574585 is the number of days returned by the subtraction...
注意:这还没有经过真正的测试,已经超出了我的脑海.
这篇关于Oracle日期减法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!