发布于 2022-11-24 06:41:48
"whereMonth“只比较月份数,而不是年份
选项1:
UserData:select(DB::raw("count(phone) as total"))
->whereBetween('creation_date',
[
Carbon::now()->startOfMonth(),
Carbon::now()->endOfMonth()
])
->get();备选方案2:
UserData:select(DB::raw("count(phone) as total"))
->whereYear('creation_date', Carbon::now()->year)
->whereMonth('creation_date', Carbon::now()->month)
->get();发布于 2022-11-24 07:12:35
这里的项目是一种模式。
$data = Item::select('*')
->whereMonth('created_at', Carbon::now()->month)
->get();
print_r($data);发布于 2022-11-24 07:38:39
您实际上需要一个完整的日期,使用的是whereMonth,而不仅仅是这个月的整数。
$data = UserData::whereMonth('creation_date', Carbon::now())->get();
return view('kpidata', compact('data'));此外,如果您只想显示记录计数,只需执行以下操作:
$data = UserData::whereMonth('creation_date', Carbon::now())->count();https://stackoverflow.com/questions/74556477
复制相似问题