Laravel - 小于/大于日期语法

新手上路,请多包涵

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

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

原文由 Selim 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 938
1 个回答

使用 Carbon 实例:

 $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();

原文由 jeanj 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题