How can i do a query to check if any records exist in my mysql table within 3 minutes of the currenct time?
| SitePoint Sponsor |



How can i do a query to check if any records exist in my mysql table within 3 minutes of the currenct time?

quite easy, save a timestamp / datetime when you insert a row and then use a limitation of ... timestamp >= NOW() - INTERVAL 3 MINUTE

By adding a column for creation date, e.g.
Populate it on insertion with CURRENT_TIMESTAMPCode:creation_date TIMESTAMP,
Now, calculate the difference in minutes from the creation date until now using TIMESTAMPDIFF as follows:
Code:SELECT * FROM my_table WHERE timestampdiff(MINUTE, creation_date, now())<3
Bookmarks