Laravel Eloquent whereMonth() Query Example

10-Apr-2023

.

Admin

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', '<=', '07')

->get();

dd($users);

}

Example 4:

/**

* The attributes that are mass assignable.

*

* @var array

*/

public function index()

{

$users = DB::table('users')

->whereMonth('created_at', '=', '07')

->get();

dd($users);

}

It will help you...

#Laravel 7

#Laravel

#Laravel 6