我无法获取仅在昨天早上6点到今天早上6点之间显示结果的查询。使用sql server 2008.我有一个timestamp列,其类型为datetime
答案 0 :(得分:5)
select * from your_table
where ts_col between
dateadd(hour, 6, DATEADD(day, DATEDIFF(day, 0, GETDATE()), -1))
and dateadd(hour, 6, DATEADD(day, DATEDIFF(day, 0, GETDATE()), 0));
答案 1 :(得分:0)
where DATEDIFF(SECOND, CAST(GETDATE() as DATE), ts_column) BETWEEN -21600 AND 21600