In this tutorial, we will see how to use whereMonth query in laravel. whereMonth() will help to condition for get specific month records from date.

Given below are examples for whereMonth query in laravel



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);
    
}


I hope this example helps you.