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? 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. 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. Link to comment https://forums.phpfreaks.com/topic/149250-solved-date_sub-problem/#findComment-783876 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.