【问题标题】:How to chek column date in a table 10 minutes less than current time如何检查表中的列日期比当前时间少 10 分钟
【发布时间】:2016-12-01 00:01:19
【问题描述】:

我想检查表格列中的时间距离当前时间不到 10 分钟。 我想检查 Laravel 查询中的 where 子句。

【问题讨论】:

  • ... WHERE your_column < NOW() - INTERVAL 10 MINUTE...

标签: mysql laravel


【解决方案1】:

让我们使用 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();

【讨论】:

    【解决方案2】:

    您可以尝试添加类似的 where 子句

    SELCT * FROM MYTABLE WHERE MYCOL < NOW() - INTERVAL 10 MINUTE
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-27
      • 1970-01-01
      • 2021-03-14
      • 2021-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-03
      相关资源
      最近更新 更多