In SQL you use the
GETDATE()
function to get the current date and time or if you want just the date, you need to remove the time portion which can be done like this:
DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()))
The
DATEADD
function can be used to reduce that date by 30 days:
DATEADD(days, -30, GETDATE())
You then use the
WHERE
clause of your statement to filter the result.
The result being something like this:
DECLARE @EarliestDate AS DATETIME
SET @EarliestDate = DATEADD(days, -3, DATEDIFF(dd, 0, GETDATE()))
SELECT
*
FROM
dbo.MyTable
WHERE
MyDateField > @EarliestDate