Get time interval in mysql

hearmeroar picture hearmeroar · Nov 13, 2013 · Viewed 15.9k times · Source

is there a query for me to get the time interval - One minute, five minutes, quarter hour, half hour, hour, and day? I use MySQL as a database.

Answer

AwokeKnowing picture AwokeKnowing · Nov 14, 2013

to get a range, like from 30 to 45 minutes ago, do like this

SELECT * FROM tbl 
WHERE tbl.mydate > DATE(DATE_sub(NOW(), INTERVAL 45 MINUTE)) 
AND tbl.mydate < DATE(DATE_sub(NOW(), INTERVAL 30 MINUTE));