I was looking at:
MySQL Select rows where timestamp column between now and 10 minutes ago
I have a col named creation_date
holding a datetime stamp: 2013-09-10 11:06:42
I would like to pull all records that are OLDER than 15 minutes using:
WHERE creation_date >= DATE_SUB(NOW(),INTERVAL 15 MINUTE)
However the query always returns 0 results, even with items older then 15 minutes present in the database.
SELECT col1, col2, col3 FROM table WHERE DATE_ADD(last_seen, INTERVAL 10 MINUTE) >= NOW();
The DATETIME type is used for values that contain both date and time parts. MySQL retrieves and displays DATETIME values in ' YYYY-MM-DD hh:mm:ss ' format. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59' . The TIMESTAMP data type is used for values that contain both date and time parts.
The DATE type is used for values with a date part but no time part. MySQL retrieves and displays DATE values in ' YYYY-MM-DD ' format. The supported range is '1000-01-01' to '9999-12-31' . The DATETIME type is used for values that contain both date and time parts.
TIMESTAMP is four bytes vs eight bytes for DATETIME . Timestamps are also lighter on the database and indexed faster. The DATETIME type is used when you need values that contain both date and time information. MySQL retrieves and displays DATETIME values in YYYY-MM-DD HH:MM:SS format.
older would be WHERE creation_date < DATE_SUB(NOW(),INTERVAL 15 MINUTE)
There are many ways to achieve this with INTERVAL
. I will present three:
first:
WHERE creation_date < DATE_SUB( NOW(), INTERVAL 15 MINUTE )
second:
WHERE creation_date < NOW() - INTERVAL 15 MINUTE
third:
WHERE creation_date < NOW() + INTERVAL -15 MINUTE
Inspirtion
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With