Laravel Eloquent whereMonth() Query Example

Admin   Laravel   196  2021-03-15 21:00:07

Hi Guys,

In this example,I will learn you how to use whereMonth query in laravel.you can easy and simply use whereMonth query in laravel.

whereMonth() will help to condition for get specific month records from date. for example if you have several records available with current timestamps then also you can simply condition with that timestamps column. you can see bellow example with output.

Example 1:

 

/**

* The attributes that are mass assignable.

*

* @var array

*/

public function index()

{

$users = User::whereMonth('created_at', '=', '07')

->get();

dd($users);

}

Example 2:

 

/**

* The attributes that are mass assignable.

*

* @var array

*/

public function index()

{

$users = User::whereMonth('created_at', '>=', '07')

->get();

dd($users);

}

Example 3:

 

/**

* The attributes that are mass assignable.

*

* @var array

*/

public function index()

{

$users = User::whereMonth('created_at', '