sql delete statement where date is greater than 30 days

Alex picture Alex · Dec 6, 2010 · Viewed 197.3k times · Source

I need a SQL statement to delete row that are older than 30 days.

My table events has a field date that contains the date and the time it was inserted in the database.

Will this work?
SELECT * from Results WHERE [Date] >= DATEADD(d, -30, getdate())

Answer

Colin Mackay picture Colin Mackay · Dec 6, 2010

Use DATEADD in your WHERE clause:

...
WHERE date < DATEADD(day, -30, GETDATE())

You can also use abbreviation d or dd instead of day.