有一个时间字段记录的值是NOW() 包含了日期和时间 如何筛选

解决方案 »

  1.   

    select * from tb where datepart(hh,时间字段)>=10 and datepart(hh,时间字段)<=20 
      

  2.   

    datepart(hh,col) between 8 and 22
      

  3.   

    SELECT * FROM [表名]
    WHERE DATEPART(HH,[时间字段名]) BETWEEN 22 AND 24 
    OR DATEPART(HH,[时间字段名]) BETWEEN 0 AND 7
      

  4.   

    select * from  [table] where datepart(hh,getdate())>='22' And datepart(hh,getdate())<=8
      

  5.   


    select * from tb where datepart(hh,时间字段)>=22 or datepart(hh,时间字段)<=8
      

  6.   

    select * from datepart(hh,时间字段) between 8 and 22
      

  7.   

    select * from tb
    where convert(varchar(2),[date],108)<='08'
    and convert(varchar(2),[date],108)>='22'
      

  8.   

    select * from  [table] where datepart(hh,getdate())>=22 And datepart(hh,getdate())<=8
      

  9.   

    select * from tb where datepart(hh,dt) between 22 and 24 or datepart(hh,dt) between 0 and 8select * from tb where datepart(hh,dt) between 22 and 23 or datepart(hh,dt) between 0 and 7
      

  10.   

    select * from tb where datepart(hh,getdate())>='22' And datepart(hh,getdate())<=8
      

  11.   

    --含八点(到九点之前)
    select * from tb where datepart(hh,dt) between 22 and 24 or datepart(hh,dt) between 0 and 8 --不含八点
    select * from tb where datepart(hh,dt) between 22 and 24 or datepart(hh,dt) between 0 and 7 
     
     
      

  12.   

    取昨晚10:00到今早8:00的数据
    select * from [表名] where datepart(hh,getdate()-1)>='22' And datepart(hh,getdate())<=8