MySqli - select from db based on time difference with CURTIME() or SUBTIME() I have a db with some customers data. There I store their last login time as datetime.

I want to run a cron php script every min which will query mysqli for their last login datetime and if that was more than 20 mins in the past i will run some js popup etc (something like NOW() - last_login).

Anyway I am trying to query the db directly for that kind of users based on that 20 min time difference.

With php it's easy to filter results but I want to bring directly results from my mysql db without any intermediate process from php.

How can I accomplish this?
Ok, i 've found the solution and i want to share it with you.

SELECT * FROM tbl_name WHERE dt_column &lt; DATE_SUB(NOW(), INTERVAL 20 MINUTE)


This brings all entries were last login  was more than 20 mins in the past.