date difference in mysql
What is the mysql select query for selecting a entries that was updated over 3 hours ago? I am storing a column called last_update_time in the table, and I want to compare that time with the current time to select all entries that was updated over 3 hours ago. All the time开发者_JAVA技巧s are stored as DATETIME in the database
Just use INTERVAL :
SELECT col1, col2
FROM your_table
WHERE col_date < NOW() - INTERVAL 3 HOUR;
This would retrieve rows where col_date is older than 3 hours ago. This allows you to use an index if possible.
精彩评论