SQL Get All Records Older Than 30 Days

Delete rows with date older than 30 days with SQL Server query

Use DATEADD in your WHERE clause:

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

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

sql delete all rows older than 30 days

The following code will delete the records of messages that are older than 30 days

DELETE FROM messages WHERE sentOn < NOW() - INTERVAL 30 DAY;

The NOW() method in MySQL is used to pick the current date with time. INTERVAL 30 DAY used for subtracting 30 days from the current date.
After the above query, you can check the current table using the SELECT statement. Thank you!

Show sql records which is 30 days older than added date

select distinct Convert(nvarchar(50), a.no) ,name ,name2 ,'test' ,date1 ,'Pending' 
from table1 a
full outer join
dbo.table2 g
on g.no = a.no
where date2 >= '2017-05-27 00:00:00.000' and datediff(dd,date1,getdate())<= 30

The query will return results after date2 as well as stop resulting the same once when date1 and current date differennce is greater than 30 days.

SQL Get all records older than 30 days

Try something like:

SELECT * from profiles WHERE to_timestamp(last_login) < NOW() - INTERVAL '30 days' 

Quote from the manual:

A single-argument to_timestamp function is also available; it accepts a double precision argument and converts from Unix epoch (seconds since 1970-01-01 00:00:00+00) to timestamp with time zone. (Integer Unix epochs are implicitly cast to double precision.)

SQL to filter for records more than 30 days old

in Oracle, when you subtract dates, by default you get the difference in days, e.g.

select * from my_table where (date_1 - date_2) > 30

should return the records whose date difference is greater than 30 days.
To make your query dynamic, you parameterize it, so instead of using hard coded date values, you use:

select * from my_table where (:date_1 - :date_2) > :threshold 

If you are using oracle sql developer to run such a query, it will pop up a window for you to specify the values for your paramteres; the ones preceded with colon.



Related Topics



Leave a reply



Submit