diferencia de fecha en 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 times are stored as DATETIME in the database

preguntado el 27 de agosto de 11 a las 17:08

1 Respuestas

Just use INTERVAL :

SELECT col1, col2
  FROM your_table
 WHERE col_date < NOW() - INTERVAL 3 HOUR;

This would retrieve rows where col_date is mayor than 3 hours ago. This allows you to use an index if possible.

Respondido 27 ago 11, 21:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.