Select all entries created in an hour.

startTimestamp < date_sub(curdate(), interval 1 hour) 

Will the query (under) above return all records created in an hour? If there is no one, please show me the correct option? A full query might look like this:

 select * from table where startTimestamp < date_sub(curdate(), interval 1 hour); 
+6
source share
1 answer

Instead of CURDATE() use NOW() and use >= , not < , since you want the timestamps to be longer than the timestamp from one hour ago. CURDATE() returns only the portion of the date, where NOW() returns both the date and time.

 startTimestamp >= date_sub(NOW(), interval 1 hour) 

For example, in my time zone this is 12:28

 SELECT NOW(), date_sub(NOW(), interval 1 hour); 2011-09-13 12:28:53 2011-09-13 11:28:53 

All together what you need:

 select * from table where startTimestamp >= date_sub(NOW(), interval 1 hour); 
+15
source

Source: https://habr.com/ru/post/897250/


All Articles