Reputation: 526
How to do you query created_at date only equals to Carbon::now() date only in laravel query builder.?
App\Table::where('created_at', '=' ,Carbon/Carbon:now() )->get();
Upvotes: 1
Views: 3180
Reputation: 3712
No Need to use anything just check whereDate For Date
App\Table::whereDate('created_at', '=' ,Carbon/Carbon:now() )->get();
among this whereMonth for Month and whereDay for date
check this link https://laravel.com/docs/5.8/queries#whereDate%20/%20whereMonth%20/%20whereDay%20/%20whereYear%20/%20whereTime
Upvotes: 1
Reputation: 7344
You can use Mysql's
default CURDATE
function with laravel query builder's Raw sql.
DB::table('posts')->select(DB::raw('*'))
->whereRaw('Date(created_at) = CURDATE()')->get();
Or
App\Table::where('created_at', '=', Carbon::today())
Upvotes: 1
Reputation: 9464
You can opt for the following kind of construct:
App\Table::whereDate('created_at', '=', now()->toDateString())->get();
Upvotes: 2