如何在Laravel中添加“在今天之内”(即从00:00:00到23:59:59)?
$grpcnt = DB::table('groups')
->where('owner_id', $u_id)
->whereBetween('created_at', xxx,xxx)
->count();
发布于 2019-07-27 11:32:29
如果你想得到今天组的数量,你可以这样使用。
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();
发布于 2019-07-27 11:34:18
你可以使用carbon来做这件事,包括一天的开始和结束
$grpcnt = DB::table('groups')
->where('owner_id', $u_id)
->whereBetween('created_at', [ Carbon::now()->startOfDay(),Carbon::now()->endOfDay()])
->count();
https://stackoverflow.com/questions/57231666
复制相似问题