有两个日期字段(indate,outdate)。显示如2012-05-30 17:55:29。outdate与indate之差小于24小时。求SQL

如题所述

oracle 的话没有datediff 函数,需要这样处理,想要差值为天,日期直接相减,想要差值为小时,结果*24,想要差值为秒结果*24*3600,毫秒如此类推;
select round(to_number(outdate-indate) * 24,2),outdate,ndate
from table
where to_number(outdate-indate) * 24 < 24

----msmql,access,sybase 中有datediff 函数计算时间差值可以直接用追问

编译错误啊。提示:
14:23:44 [SELECT - 0 row(s), 0.000 secs] [Error Code: -9700, SQL State: IX000] Routine (to_number) ambiguous - more than one routine resolves to given signature.
... 1 statement(s) executed, 0 row(s) affected, exec/fetch time: 0.000/0.000 sec [0 successful, 0 warnings, 1 errors]

追答

是 oracle 数据库么?

追问

是imformix。一直减不出来啊

追答

如果直接两个日期相减。informix 会得到什么结果?

-----------------------------

试一试 select outdate,indate from table date(outdate) - date(indate) <1

温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-08-10
select indate,outdate from table where datediff( hour ,indate ,outdate )希望能够帮到你!
第2个回答  2012-08-10
能说明具体点吗 你是想算2个日期之间的差值 还是怎么的 描述清楚点 我可以帮你追问

首先非常感谢你。
我的问题是,table表下面有两个字段indate,outdate。其字段格式都是“DATETIME YEAR TO SECOND” 比如显示的值是“2012-05-30 17:55:29.0”
现在需求是,选outdate里面最大的减去indate里面最小的,小于24小时。就是outdate-indate<=24。我研究很久了,没弄出来。.求高人指点