Standage
Standage

Reputation: 1517

Get data from a date - 1 day

I thought this would work but its not bring back any results:

some sql statement....

AND (DateDiff(Day, irs.timeStamp, GETDATE()) = 1) 

It brings back all the results for today if I change the result to 0 but not for yesterday if I change it to 1 or -1?

Upvotes: 0

Views: 4099

Answers (1)

Aaron Bertrand
Aaron Bertrand

Reputation: 280262

You should use an open-ended range, e.g. to get all data from yesterday, you want everything equal to or after midnight but before midnight today.

AND irs.timeStamp >= CONVERT(DATE, DATEADD(DAY, -1, GETDATE()))
AND irs.timeStamp < CONVERT(DATE, GETDATE());

Upvotes: 5

Related Questions