Eiolon Posted March 13, 2009 Share Posted March 13, 2009 I am trying to query for a code and want it to return a result only if it was used within the last 30 minutes. mysql> SELECT code, last_used FROM codes WHERE code = '234-246-248' AND DATE_SUB(CURDATE(),INTERVAL 30 MINUTE) <= last_used; +-------------+---------------------+ | code | last_used | +-------------+---------------------+ | 234-246-248 | 2009-03-13 06:46:05 | +-------------+---------------------+ 1 row in set (0.00 sec) It's been well over an hour since the code was last used but it is still returning a result. Any clues? Quote Link to comment https://forums.phpfreaks.com/topic/149250-solved-date_sub-problem/ Share on other sites More sharing options...
fenway Posted March 13, 2009 Share Posted March 13, 2009 probably because you're mixing CURDATE() and a TIME-based INTERVAL -- use NOW() instead. Quote Link to comment https://forums.phpfreaks.com/topic/149250-solved-date_sub-problem/#findComment-783869 Share on other sites More sharing options...
Eiolon Posted March 13, 2009 Author Share Posted March 13, 2009 Thanks very much, that is what was wrong. Quote Link to comment https://forums.phpfreaks.com/topic/149250-solved-date_sub-problem/#findComment-783876 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.