如何按日期获取注册用户数并立即获得结果?

时间:2017-11-09 02:16:22

标签: php mysql laravel laravel-5 eloquent

$rows = Registrant::select(DB::raw('count(*) as number, created_at'))
                      ->whereBetween( DB::raw('date(created_at)'), [$fromDate, $tillDate] )
                      ->groupBy(DB::raw('date(created_at)'))
                      ->get();

以上查询给出了以下结果:

[{"number":4,"created_at":"2017-11-08 17:57:37"}]

这是完全正确的,除了我只想在没有时间的情况下出现约会(17:57:37)?如何删除时间:

[{"number":4,"created_at":"2017-11-08"}]

1 个答案:

答案 0 :(得分:1)

简单地替换

DB::raw('count(*) as number, created_at')

DB::raw('count(*) as number, DATE(created_at)')