Reputation: 59
I am having trouble getting a query that only displays results between 6am yesterday and 6am today. Using sql server 2008. I have a timestamp column with type datetime
Upvotes: 1
Views: 58
Reputation: 22478
where DATEDIFF(SECOND, CAST(GETDATE() as DATE), ts_column) BETWEEN -21600 AND 21600
Upvotes: 0
Reputation: 204924
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));
Upvotes: 5