日期:2014-05-18  浏览次数:20562 次

又是关于时间的查询!
ID                                           date
F44FC345B10F050 2006/01/03   21:29:24
F44FC38A910F050 2006/01/07   01:25:38
F44FC3EE510F050 2006/01/03   23:32:22
F488035EB10F050 2006/01/05   08:38:50
F50B42AFC10F050 2006/01/03   13:35:32
F50B42AFC10F050 2006/01/08   23:55:12

比如
以上数据,想查询12:00~20:00的ID(不管日期,只看具体时间)
谢谢啦!


------解决方案--------------------
select *
from table
where datepart(date,hh) > =12 and datepart(date,hh) <= 20
------解决方案--------------------
select *
from table
where datepart(date,hh) BETWEEN 12 and 20
------解决方案--------------------
select * from table
where substrint(convert(varchar,[date],120),12,16) between '12:05 ' and '20:15 '
------解决方案--------------------
select * from table
where substring(convert(varchar,[date],120),12,16) between '12:05 ' and '20:15 '

------解决方案--------------------
select *
from table
where datepart(date,hh) > =12 and datepart(date,hh) < 21

------解决方案--------------------
--或者
select * from table
where substrint(convert(varchar,[date],108),1,5) between '12:05 ' and '20:15 '

------解决方案--------------------
select *
from table
where DATEPART(hour, [date]) between 12 and 20