表A
字段
a b
001 2008-4-15 9:03:08
002 2008-4-16 17:03:08
003 2008-4-17 2:03:08
004 2008-4-17 13:03:08
005 2008-4-17 23:03:08查找b的时间和当前时间24小时内的
字段
a b
001 2008-4-15 9:03:08
002 2008-4-16 17:03:08
003 2008-4-17 2:03:08
004 2008-4-17 13:03:08
005 2008-4-17 23:03:08查找b的时间和当前时间24小时内的
from tb
where datediff(minute,b,getdate())<=(24*60)
select * from tb where datediff(hour , b , getdate()) <= 24
set nocount on
create table test(a varchar(20),b datetime)
insert into test select '001','2008-4-15 9:03:08'
insert into test select '002','2008-4-16 17:03:08'
insert into test select '003','2008-4-17 2:03:08'
insert into test select '004','2008-4-17 13:03:08'
insert into test select '005','2008-4-17 23:03:08'
go
--测试
select * from test where datediff(hh,b,getdate())<24--删除测试环境
drop table test
set nocount off