如何查询一个表,使其只获取与特定月份和年份匹配的记录,例如Y-m,即2020-10。“created_at”列的。
这就是我目前正在做的事情:
School::where('user_id', 1)->where('created_at', '=', '2020-10')->count();发布于 2021-02-06 23:02:07
我建议为您的过滤器创建一个日期范围,这样您的查询将保持为
$date = \Carbon\Carbon::parse($year."-".$month."-01");
$start = $date->startOfMonth()->format('Y-m-d H:i:s');
$end = $date->endOfMonth()->format('Y-m-d H:i:s');
School::where('user_id', 1)
->whereBetween('created_at', [$start, $end])
->count();https://stackoverflow.com/questions/66078106
复制相似问题