Laravel where Month and Year Query Example

Laravel where Month and year function example; Through this tutorial, i am going to show you how to use whereMonth() and whereYear() function with eloquent queries in laravel apps.

Example 1 – Laravel WhereMonth()

Now, i am going to show you how to use whereMonth() function with db::table() in laravel app; as follows:

$users = DB::table('users')
                ->whereMonth('created_at', '12')
                ->get();

Note that:- The whereMonth method may be used to compare a column’s value against a specific month:

Example 2 – Laravel WhereYear()

Now, i am going to show you how to use whereYear() function with db::table() in laravel app; as follows:

$users = DB::table('users')
                ->whereYear('created_at', '2016')
                ->get();

Note that:- The whereYear method may be used to compare a column’s value against a specific year.

Be First to Comment

Leave a Reply

Your email address will not be published.