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
How to Deploy Laravel on Heroku with Database
How to Deploy Laravel on Herok...

In this article, we will see how to deploy laravel on heroku with database. Heroku is a cloud platform as...

Read More

Feb-12-2021

How to Generate Fake Data using Tinker in Laravel 11
How to Generate Fake Data usin...

Hello, laravel web developers! In this article, we'll see how to generate fake data using Tinker in laravel 11....

Read More

May-22-2024

Laravel 9 Livewire Toastr Notification
Laravel 9 Livewire Toastr Noti...

In this article, we will see laravel 9 livewire toastr notification. Here, we will learn how to create toastr notif...

Read More

Nov-28-2022

Laravel 8 Send Mail using Queue
Laravel 8 Send Mail using Queu...

In this tutorial I will show you laravel 8 send mail using queue, many time we can see some process to take mo...

Read More

Sep-24-2021