简体   繁体   中英

How to type within today From 00:00:00 to 23:59:59 in Laravel

How to add "within today" (ie From 00:00:00 to 23:59:59) in Laravel ?

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

If you want to get count of today group then you may use like this.

DB::table('groups')->where('owner_id', $u_id)
                  ->whereDate('created_at', Carbon::today())
                  ->count();

Or as per your requirement

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

You can use carbon for this, with start of the day and end of the day

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM