Laravel - 其中小于/大于日期语法

2022-08-30 13:32:25

这未显示正确的计数。什么是正确的语法?

$this->data['Tasks'] = \DB::table('tb_tasks')->where('Status', 'like', 'Open%')->whereDate('DeadLine', '>', 'CURDATE()')->count();

答案 1

使用碳实例:

$this->data['Tasks'] = \DB::table('tb_tasks')->where('Status', 'like', 'Open%')->whereDate('DeadLine', '>', Carbon::now())->count();

您还可以使用帮助程序now()

$this->data['Tasks'] = \DB::table('tb_tasks')->where('Status', 'like', 'Open%')->whereDate('DeadLine', '>', now())->count();

答案 2

使用 DB::raw

->where('datefield', '>', \DB::raw('NOW()'))

推荐