Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sql query to select from 1 hour ago?

Tags:

sql

mysql

I have this query but I want to change the date to delete everything that is from more than 1 hour ago based on the server time (or if not possible by server time by post date). How do I do that?

DELETE FROM wp_posts  WHERE post_date < '2008-06-06 19:18:00'     AND post_status = 'publish' 
like image 354
Mark Avatar asked Dec 15 '10 15:12

Mark


People also ask

How do I get last 1 hour data in SQL?

Here is the SQL to show latest time using now() function. Here is the SQL to get last 1 hour data in MySQL. In the above query, we select only those rows whose order_date falls within past 1 hour interval. We use INTERVAL clause to easily substract 1 hour interval from present time obtained using now() function.

How do I get HH MM SS from date in SQL?

SELECT convert(varchar, getdate(), 108) outputs as hh:mm:ss .

Can you subtract time in SQL?

MySQL SUBTIME() FunctionThe SUBTIME() function subtracts time from a time/datetime expression and then returns the new time/datetime.

Is hour a function in SQL?

MySQL HOUR() Function The HOUR() function returns the hour part for a given date (from 0 to 838).


1 Answers

Use:

DELETE FROM wp_posts  WHERE post_date < DATE_SUB(NOW(), INTERVAL '1' HOUR)    AND post_status = 'publish' 

Reference:

  • DATE_ADD
  • DATE_SUB
like image 130
OMG Ponies Avatar answered Oct 12 '22 06:10

OMG Ponies