SQL - Delete all Records older than specified Date or Time

Post Reply
admin
Site Admin
Posts: 31
Joined: Mon Sep 16, 2024 5:00 pm
Contact:

SQL - Delete all Records older than specified Date or Time

Post: # 245Post admin »

MY SQL
30 Days

Code: Select all

DELETE FROM <table_name> where <Date Field> < now() - INTERVAL 30 DAY;
1 Month

Code: Select all

DELETE FROM <table_name> where <Date Field> < now() - INTERVAL 1 MONTH;
MS SQL Server
30 Days

Code: Select all

DELETE FROM <table_name> WHERE  date < DATEADD(day, -30, GETDATE())
1 Month

Code: Select all

DELETE FROM <table_name> WHERE  date < DATEADD(MONTH, -5, GETDATE()
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest