Jump to content

selecting rows within 15 minutes of current time


scarhand

Recommended Posts

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());

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.