简体   繁体   English

在mysql中select查询在php中选择15分钟前的数据

[英]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.我想在过去 15 分钟内使用res_time选择数据。 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如果您使用的是 PHP,那么您可以执行此操作

$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.如果您想要纯 SQL 解决方案,请遵循其他提到的解决方案。

Cheers !!!干杯!!!

Try this if you are not using unix timestamp:如果您不使用 unix 时间戳,请尝试以下操作:

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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