0

I need to pull in the last 48 hours of data, however I only need 24 hours. The reason why I am pulling in more data than necessary is because I do not know what time this script is going to run and the [data].[table] source might not have a full 24 hours. I need a full days data between these two specific times 00:00:00 and 23:59:59.

For example: If today is 2022-04-25, then I want to bring in data between 2022-04-24 00:00:00 2022-04-24 23:59:59.

SELECT [ID],[Timestamp],[Value]
FROM [data].[table]  
Where [Timestamp] >= DateAdd(day, -2, getdate())
Starbucks
  • 1,448
  • 3
  • 21
  • 49
  • 1
    Just use traditional date ranges: `TimeStamp >= '20220424' and TimeStamp < '20220425'` Getting yesterday's date (and today's) is simple with `DATEADD` and if you don't want a time portion then `CONVERT` a `date`. – Thom A Apr 25 '22 at 12:30
  • 2
    Side note: `timestamp` is a poor choice of a column name in SQL Server; `timestamp` is a *deprecated* synonym of `rowversion` which is a `binary(8)` value and it has **nothing** to do with date and times. – Thom A Apr 25 '22 at 12:31

0 Answers0