This could be used to query records which were created in last 5 minutes, 30 minutes, 60 minutes, 120 minutes, etc with DATE_SUB(NOW(), INTERVAL 400 MINUTE)
For example, we have a MySQL log table has structure like this:
CREATE TABLE IF NOT EXISTS `code_used_logs` ( `id` BIGINT(20) NOT NULL AUTO_INCREMENT, `code` VARCHAR(50) NOT NULL `created_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=14 ; |
And we already have some records have been created. Now we will query which records have been created in last 600 minutes (10 hours).
SELECT id, code, created_date, DATE_SUB( NOW( ) , INTERVAL 600 MINUTE ) FROM mc_code_used_logs WHERE created_date > DATE_SUB( NOW( ) , INTERVAL 600 MINUTE ) LIMIT 0 , 30 |
Output: