【发布时间】:2016-12-01 00:01:19
【问题描述】:
我想检查表格列中的时间距离当前时间不到 10 分钟。 我想检查 Laravel 查询中的 where 子句。
【问题讨论】:
-
... WHERE your_column < NOW() - INTERVAL 10 MINUTE...
我想检查表格列中的时间距离当前时间不到 10 分钟。 我想检查 Laravel 查询中的 where 子句。
【问题讨论】:
... WHERE your_column < NOW() - INTERVAL 10 MINUTE...
让我们使用 PHP 查找比当前日期时间早 10 分钟的日期时间。让我们在代码中说 $formatted_date。 然后找到所有日期时间小于 $formatted_date 的记录。请看下面,如果您有任何疑问,请告诉我。
$date = new DateTime;
$current_date = $date->format('Y-m-d H:i:s');
$date->modify('-10 minutes');
$formatted_date = $date->format('Y-m-d H:i:s');
$result = DB::table('table_name')->where('datecolumn','<=',$formatted_date)->get();
另一种方式是:
$result = DB::table('table_name')->where(TIMESTAMPDIFF(MINUTE,'datecolumn',$current_date),'<=',10)->get();
【讨论】:
您可以尝试添加类似的 where 子句
SELCT * FROM MYTABLE WHERE MYCOL < NOW() - INTERVAL 10 MINUTE
【讨论】: