Reputation: 5249
I am trying to get all the records from the last 2 days but excluding today's date. I want to get name and location where date submitted is included for the last 2 days only. The data type for date_submitted
is datetime
.
select name, location
from myTable
where date_submitted in (select CAST(FLOOR(CAST(GETDATE() AS FLOAT)) AS DATETIME))
Upvotes: 0
Views: 22731
Reputation: 156978
Don't use in
, use >=
. You can also use dateadd
:
where date_submitted >= cast(dateadd(day, -2, getdate()) as date)
and date_submitted < cast(getdate() as date)
Upvotes: 11