简体   繁体   中英

select query in mysql to select the data before 15 minutes in php

I have a table:

在此处输入图片说明

I want to select data with res_time within the past 15 minutes. I am using:

SELECT * FROM test WHERE res_time >= DATE_SUB(now(), INTERVAL 15 MINUTE).

SELECT * FROM `test` WHERE res_time between timestamp(DATE_SUB(NOW(), INTERVAL 15 MINUTE)) AND timestamp(NOW()).

您可以尝试以下查询。

SELECT * FROM test WHERE res_time >= DATE_SUB(CURDATE(),INTERVAL 15 MINUTE)

If you are using PHP then you can do this

$beforeTime = date("Y-m-d h:i:s",strtotime("-15 minutes"));
$query = "select * from test where res_time >= '$beforeTime' " ;

If you want the pure SQL solution then follow other mentioned solutions.

Cheers !!!

Try this if you are not using unix timestamp:

SELECT * FROM test WHERE res_time >= DATE_SUB(CURDATE(), INTERVAL 15 MINUTE);

or

SELECT * FROM test WHERE FROM_UNIXTIME(res_time) >= DATE_SUB(CURDATE(), INTERVAL 15 MINUTE)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM