1

我无法获得仅在昨天早上 6 点到今天早上 6 点之间显示结果的查询。使用 sql server 2008。我有一个类型为 datetime 的时间戳列

4

2 回答 2

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));

SQLFiddle 示例

于 2012-11-01T16:19:43.443 回答
0

where DATEDIFF(SECOND, CAST(GETDATE() as DATE), ts_column) BETWEEN -21600 AND 21600

于 2012-11-01T16:37:42.783 回答