Pulling Records Older Than a Specific Time Using MySQL
When attempting to select records with a datetime column falling within a specific time range, such as those older than 15 minutes, you may encounter unexpected results. The query provided in the question, which employs the >= operator, retrieves no records. To rectify this issue, you should use the < operator instead.
Modified Query:
<code class="mysql">WHERE creation_date < DATE_SUB(NOW(),INTERVAL 15 MINUTE)
Explanation:
The modified query correctly uses the < operator to specify that creation_date must be strictly less than the current time minus 15 minutes. This operation ensures that only records older than 15 minutes are retrieved.
Note:
When dealing with datetime comparisons, it's crucial to use the appropriate operator. The >= operator, commonly used to retrieve records that are greater than or equal to a specific time, does not suit the requirement in this query.
The above is the detailed content of Why Does My MySQL Query Not Retrieve Records Older Than 15 Minutes?. For more information, please follow other related articles on the PHP Chinese website!