Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

select query for time interval in mysql and php

Tags:

php

mysql

select query to select all records that were inserted in 15 minutes.for ex if now time is 10:00 then it shoulld fetch all record inserted from 9:45 to 10:00

like image 577
mayuri Avatar asked Jul 08 '10 08:07

mayuri


2 Answers

Assuming you have a DATETIME column named created in your table:

SELECT id FROM tablename 
WHERE ((created > DATE_SUB(NOW(), INTERVAL 15 MINUTE))
  AND (created < NOW()))
like image 149
Pekka Avatar answered Nov 14 '22 22:11

Pekka


select * from table WHERE datetimeField BETWEEN date_add(NOW(),INTERVAL -15 MINUTE) AND NOW();
like image 40
Māris Kiseļovs Avatar answered Nov 14 '22 23:11

Māris Kiseļovs