Php 如何在Laravel中键入从00:00:00到23:59:59的今天

Php 如何在Laravel中键入从00:00:00到23:59:59的今天,php,laravel,Php,Laravel,如何在Laravel中添加“今天内”(即从00:00:00到23:59:59) $grpcnt = DB::table('groups') ->where('owner_id', $u_id) ->whereBetween('created_at', xxx,xxx) ->count(); 如果你想得到今天组的计数,那么你可以这样使用 DB:

如何在Laravel中添加“今天内”(即从00:00:00到23:59:59)

$grpcnt = DB::table('groups') 
                      ->where('owner_id', $u_id)
                      ->whereBetween('created_at', xxx,xxx)
                      ->count();


如果你想得到今天组的计数,那么你可以这样使用

DB::table('groups')->where('owner_id', $u_id)
                  ->whereDate('created_at', Carbon::today())
                  ->count();
或根据您的要求

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

你可以在一天的开始和结束时使用碳

$grpcnt = DB::table('groups') 
            ->where('owner_id', $u_id)
            ->whereBetween('created_at', [ Carbon::now()->startOfDay(),Carbon::now()->endOfDay()])
            ->count();