Laravel 9 whereDate And whereMonth Query Example

Websolutionstuff | Oct-19-2022 | Categories : Laravel

In this article, we will see laravel 9 wheredate() and wheremonth() query examples. The whereDate method may be used to compare a column's value against a date. The whereMonth method may be used to compare a column's value against a specific month. So, we will learn wheredate() in laravel 9 and wheremonth() in laravel 9.

The whereDate() through we can make conditions like date even column datatype timestamps. The whereMonth() will help to condition for getting specific month records from date.

So, let's see a whereDate() query in laravel 9 and a whereMonth() query in laravel 9.

Syntax of the whereDate()

whereDate(Column Name, Operator, Value);

 

Example 1:

In this example, we will retrieve all records which have the date 2022-10-07.

$users = DB::table('users')
                ->whereDate('created_at', '2022-10-07')
                ->get();

 

 Example 2:

In this example, we will retrieve all those records where join_date is less than equal to 2022-10-07.

$employee = DB::table('employee')
            ->whereDate('join_date','<=','2022-10-07')
            ->get();
dd($employee);

 

Syntax of the whereMonth()

whereMonth(Column Name, Value);

 

Example 3:

In this example, we will retrieve all records which have the month 12.

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

 


You might also like:

Recommended Post
Featured Post
Laravel 10 Send Mail using Markdown Template
Laravel 10 Send Mail using Mar...

Hey everyone! Ever wondered how to make your Laravel emails look sleek and professional? In this guide, I'll walk yo...

Read More

Dec-04-2023

How to Search with Pagination in Laravel 10 Vue 3
How to Search with Pagination...

Hey everyone! Ever found yourself in need of a straightforward example for integrating search and pagination in a Larave...

Read More

Jan-01-2024

How To Add jQuery Datatable Column Filter Dropdown On Top
How To Add jQuery Datatable Co...

In this article, we will see how to add a jquery datatable column filter dropdown on top. Here, we will learn how t...

Read More

Jan-19-2023

How to Export CSV File in Laravel
How to Export CSV File in Lara...

In this post we will see how to export CSV file in laravel, Export csv file in laravel is most common function...

Read More

Apr-30-2021