declare @t table
(dt datetime)insert @t
select getdate() union all
select dateadd(hour,10,getdate()) union all
select dateadd(hour,12,getdate()) union all
select dateadd(hour,-9,getdate()) union all
select dateadd(hour,20,getdate()) union all
select dateadd(hour,-20,getdate())select * from @t
where abs(datediff(hour,dt,getdate()))<=12
dt                                                     
------------------------------------------------------ 
2006-01-11 18:32:58.107
2006-01-12 04:32:58.107
2006-01-12 06:32:58.107
2006-01-11 09:32:58.107(所影响的行数为 4 行)

解决方案 »

  1.   

    select id, tit, times from XXX where times >= sysdate - 1
      

  2.   

    24小时内的数据?直接用between and 不行?还是知道某个时间值,求他之后24小时内的?
      

  3.   

    select id, tit, times from XXX where times between dateadd(hh,-24,getdate()) and getdate()
      

  4.   

    select id, tit, times from XXX where times > dateadd(hh,-24,getdate())
      

  5.   

    1、当前时间所在天的数据
    select id, tit, times from 表 where datediff(day,times,getdate())=02、距离当前时间不超过24小时的数据
    declare @date datetime
    select @date=getdate()
    select id, tit, times from 表 where times between dateadd(day,-1,@date) and dateadd(day,1,@date)
      

  6.   

    select id, tit, times from XXX where times > dateadd('d',-1,now())
      

  7.   

    select count(1) 起数,substring(时间,5,2) from tb_hzbg where
    substring(时间,1,4)=2004
    group by substring(时间,5,2)时间格式: 20041229210100结果数据:259 01
    163 02
    131 03
    143 04
    146 05
    118 06
    160 07
    116 08
    96 09
    110 10
    92 11
    103 12
      

  8.   

    若时间格式为: 2004-12-29substring 做修改即可 substring(时间,6,2)