Skip to content

Instantly share code, notes, and snippets.

@umair-me
Created April 11, 2019 12:46
Show Gist options
  • Save umair-me/08eea8500a17eac919ab0d64859183bb to your computer and use it in GitHub Desktop.
Save umair-me/08eea8500a17eac919ab0d64859183bb to your computer and use it in GitHub Desktop.
Delete older records by date
--This assumes 24 hours to the minute:
DELETE
MyTableWhere
WHERE
MyColumn < DATEADD(day, -1, GETDATE())
--This assumes yesterday midnight:
DELETE
MyTableWhere
WHERE
MyColumn < DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), -1)
https://stackoverflow.com/a/1588846/1158845
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment