如何获取当天8点至昨天8点的数据 如何获取当天8点至昨天8点的数据 ------最佳解决方案-------------------- between convert(varchar(11),getdate(),120)+'08:00:00'
and convert(varchar(11),dateadd(day,1,getdate()),120)+'08:00:00' ------其他解决方案-------------------- ---假设时间字段为odate
DECLARE @s1 datetime
DECLARE @s2 datetime
SELECT @s1 = CAST(CAST(GETDATE() AS DATE) AS VARCHAR(10)) + ' 8:00:00' --当天8点
SELECT @s2 = CAST(CAST( DATEADD("DAY", -1,GETDATE()) AS DATE) AS VARCHAR(10)) + ' 8:00:00' --昨天8点
SELECT
FROM tb
WHERE odate BETWEEN @s1 AND @s2
------其他解决方案-------------------- between convert(varchar(11),getdate(),120)+'08:00:00'
and convert(varchar(11),dateadd(day,-1,getdate()),120)+'08:00:00'
------其他解决方案-------------------- select *
from TB
where 日期 between convert(varchar(20),GETDATE()-1,23)+' 08:00:00' and convert(varchar(20),GETDATE(),23)+' 08:00:00' ------其他解决方案--------------------
between convert(varchar(11),dateadd(day,-1,getdate()),120)+'08:00:00' and
convert(varchar(11),getdate(),120)+'08:00:00'