I need to change the below MySQL code to laravel format using where, between and like operators together:
select count(id) from tbl1
where created_at BETWEEN
'2018-12-10%' AND '2018-12-12%'
I need to change the below MySQL code to laravel format using where, between and like operators together:
select count(id) from tbl1
where created_at BETWEEN
'2018-12-10%' AND '2018-12-12%'
I found the answer as below:
\DB::table('tbl1')->whereBetween('created_at',[$sdate.'%', $enddate.'%'])->count();
If you're using a Model you could use the whereBetween
method, take a look at the following example:
User::query()->whereBetween('created_at', [$start, $end])->count();