如何在 Laravel 中添加“今天内”(即从 00:00:00 到 23:59:59)?
$grpcnt = DB::table('groups')
->where('owner_id', $u_id)
->whereBetween('created_at', xxx,xxx)
->count();
Run Code Online (Sandbox Code Playgroud)
如果你想获得今天组的数量,那么你可以这样使用。
DB::table('groups')->where('owner_id', $u_id)
->whereDate('created_at', Carbon::today())
->count();
Run Code Online (Sandbox Code Playgroud)
或者根据您的要求
$start = Carbon::now()->startOfDay(); //2019-07-27 00:00:00.000000
$end = Carbon::now()->endOfDay(); //2019-07-27 23:59:59.000000
DB::table('groups')->where('owner_id', $u_id)
->whereBetween('created_at', [$start, $end])->count();
Run Code Online (Sandbox Code Playgroud)