日期:2014-05-17  浏览次数:20662 次

我想判斷ptime>=18點 and ptime<=23點59
大家好:

select * from punc_oridata where personcode='C00612' and ptime>='2012-09-19 18:00:00.000'
and ptime<='2012-09-19 23:59:00.000'

我想判斷ptime>=18點 and ptime<=23點59
請問這個要怎麼寫?

謝謝.

------解决方案--------------------
SQL code

select * from punc_oridata where personcode='C00612' 
    and convert(varchar(10),ptime,108) between '18:00:00' and '23:59:59';

------解决方案--------------------
SQL code
select * from punc_oridata where personcode='C00612' and ptime>='2012-09-19 18:00:00'
and ptime<'2012-09-20 00:00:00'

------解决方案--------------------
SQL code
select * from punc_oridata where personcode='C00612' and datediff(hh,convert(varchar(10),ptime,120),ptime)>=18

------解决方案--------------------
这个是获取小时加分钟:SELECT CONVERT(VARCHAR(2),DATEPART(hh,'2012-09-19 18:00:00.000'))+':'+CONVERT(VARCHAR(2),DATEPART(n,'2012-09-19 18:00:00.000'))