Eliminar todas las filas con marca de tiempo anterior a x días
Quiero eliminar todas las filas con marca de tiempo anterior a 180 días de una tabla específica en mi base de datos.
He probado esto:
DELETE FROM on_search WHERE search_date < DATE_SUB(NOW(), INTERVAL 180 DAY);
Pero eso eliminó todas las filas y no solo las filas de más de 6 meses.
Tengo una columna en la tabla on_search llamada search_date y contiene la hora en que se creó esa fila.
search_id search_term search_date
660779 car games 1390052553
34
Author: Brian Tompsett - 汤莱恩, 2014-01-18
2 answers
DELETE FROM on_search
WHERE search_date < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 180 DAY))
49
Author: JSR,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-01-18 16:22:24
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-01-18 16:22:24
DELETE FROM on_search WHERE search_date < NOW() - INTERVAL N DAY
Reemplace N con su recuento de días
44
Author: Ali MasudianPour,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-01-18 16:07:52
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-01-18 16:07:52