Query to test and return timed lockout in MySQL I have some functionality in my webapp that locks out users from certain behavior for a set amount of time (e.g., they have to wait 10 minutes before they can update a level). 

My query looks like this:

SELECT date_last_updated FROM levels
WHERE user_id = 123 AND date_last_updated &gt; date_sub(now(), INTERVAL 10 MINUTE);`


Please note that date_last_updated is DATETIME. 

Currently, if a row is returned I know they're still in the lockout, so that's fine for a boolean result. But just a single column row of the remaining time, in minutes as an integer would be better. That is where anything > 0 indicates both lockout is in effect, and how much time is left. 

How would I do this?
I think a more elegant solution is 

SELECT 
TIMESTAMPDIFF(MINUTE, date_last_updated, now()) as mins_since_last_update
FROM levels
WHERE id = 123


This gives me the time value as the OP requested, as an integer.