sql-server

SQL Server: Return records within X days of a date


I need a WHERE condition in SQL Server where I can return the past 7 days of activity from a given date.

Pretend I have 2 columns of dates [dateA] and [dateB]

I am looking for something like

SELECT *
FROM TABLE
WHERE [dateB] >= ([dateA] - 7 days)

Solution

  • WHERE dateB >= DATEADD(DAY, -7, dateA)
    

    Potentially useful reading...