怎样查询 昨天16:00 至 前天16:00间的数据,日期字段为rq(datetime)
搞半天搞得头疼了!
请求大家的帮助!
------解决方案--------------------
select *
from tb
where rq <= dateadd(day,-1,convert(varchar(10),GETDATE(),120)+' 16:00:00') --昨天16点
and rq >= dateadd(day,-2,convert(varchar(10),GETDATE(),120)+' 16:00:00') --前天16点
------解决方案--------------------
修改一下
where rq between CONVERT(VARCHAR(10),convert(date,dateadd(dd,-2,getdate())))+' '+'16:00:00.000' and SELECT CONVERT(VARCHAR(10),convert(date,dateadd(dd,-1,getdate())))+' '+'16:00:00.000'
------解决方案--------------------
select * from [tablename] where rq
between
convert(varchar(10),GETDATE()-2,121)+' 16:00:00.000'
and convert(varchar(10),GETDATE()-1,121)+' 16:00:00.000'
------解决方案--------------------
select * from tb where rq between CONVERT (varchar(11), dateadd(dd,-2,GETDATE()),111)+' 16:00:00' and CONVERT (varchar(11), dateadd(dd,-1,GETDATE()),111)+' 16:00:00'