WHERE datetime older than some time (eg. 15 minutes)
Question:
Why does the following query return 0 results for records older than 15 minutes, despite there being such records in the database?
<code class="sql">WHERE creation_date >= DATE_SUB(NOW(), INTERVAL 15 MINUTE)</code>
Answer:
The query should be modified to use < (less than) instead of >= (greater than or equal to) to correctly select records older than 15 minutes:
<code class="sql">WHERE creation_date < DATE_SUB(NOW(), INTERVAL 15 MINUTE)
Using >= would select records that are either equal to or greater than the current time minus 15 minutes, effectively excluding records older than 15 minutes.
The above is the detailed content of Why Does My Query Return Zero Results for Records Older Than 15 Minutes?. For more information, please follow other related articles on the PHP Chinese website!