scarhand Posted January 21, 2010 Share Posted January 21, 2010 i have a table: - id (int) - sid (int) - thetime (varchar 255) now "thetime" values are formatted as such: 2010-01-20 20:15:00 i am trying to select all rows whose 'thetime' values are within 15 minutes of the current time i have tried these queries with no luck (and no mysql errors either): mysql_query("SELECT * FROM table WHERE thetime >= NOW() - INTERVAL 15 MINUTE") or die(mysql_error()); mysql_query("SELECT * FROM table WHERE CURRENT_TIME() < thetime + INTERVAL 15 MINUTE") or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/189255-selecting-rows-within-15-minutes-of-current-time/ Share on other sites More sharing options...
scarhand Posted January 21, 2010 Author Share Posted January 21, 2010 i think i got it: $sql = mysql_query(" SELECT * FROM table WHERE thetime < NOW() + INTERVAL 15 MINUTE AND thetime > NOW() - INTERVAL 15 MINUTE ") or die(mysql_error()); if anyone can suggest a better or more accurate method, feel free to indulge me. Link to comment https://forums.phpfreaks.com/topic/189255-selecting-rows-within-15-minutes-of-current-time/#findComment-999114 Share on other sites More sharing options...
fenway Posted January 21, 2010 Share Posted January 21, 2010 Well, there is a BETWEEN operator. Link to comment https://forums.phpfreaks.com/topic/189255-selecting-rows-within-15-minutes-of-current-time/#findComment-999465 Share on other sites More sharing options...
scarhand Posted January 21, 2010 Author Share Posted January 21, 2010 ahh perfect! thanks Link to comment https://forums.phpfreaks.com/topic/189255-selecting-rows-within-15-minutes-of-current-time/#findComment-999590 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.