Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL select all the entries older than 10 days

Tags:

php

mysql

Good day all, I'm developing a small script that has to check if an entry from a MySQL database is at least older than 10 days from now. the table has a timestamp field (which is the one I would like to use, but I can change it if needed). Actually I'm using this sql string:

SELECT * 
FROM entries 
WHERE tag='$tag' 
  AND DATE(last_update) > DATE_SUB(CURDATE(), INTERVAL 10 DAY)

but I'm discovering some selected entries "younger" than 10 days so maybe I'm mistaking something. is this the right way or is better to check it via PHP (and not with the MySQL query) ?

thanks in advance.

like image 448
Matteo Bononi 'peorthyr' Avatar asked Nov 28 '22 01:11

Matteo Bononi 'peorthyr'


1 Answers

older than 10 days should be before the calculated date.

SELECT * FROM entries 
WHERE tag='$tag' AND DATE(last_update) < DATE_SUB(CURDATE(), INTERVAL 10 DAY)
like image 115
Dylan Su Avatar answered Dec 05 '22 23:12

Dylan Su