如何在Laravel中一起使用whereBetween和like运算符?

时间:2019-01-13 12:08:23

标签: mysql laravel-5

我需要使用where,between和类似的运算符将以下MySQL代码更改为laravle格式:

select count(id) from tbl1 
where created_at BETWEEN 
   '2018-12-10%' AND '2018-12-12%' 

2 个答案:

答案 0 :(得分:1)

我找到了如下答案:

\DB::table('tbl1')->whereBetween('created_at',[$sdate.'%', $enddate.'%'])->count();

答案 1 :(得分:0)

如果您使用模型,则可以使用whereBetween方法,请看以下示例: User::query()->whereBetween('created_at', [$start, $end])->count();