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);
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();
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);
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:
Hello All, In this post i will show you how to connect ftp server using php. PHP provide inbuilt functio...
May-12-2021
In this article, we will see how to create a unique slug in laravel 9. A slug is the part of a URL that i...
Sep-27-2022
In this article, we will see laravel 10 create an ajax pagination example. Here, we will learn about how to create...
Apr-17-2023
In this article, we will see laravel 9 barcode generator example. In this example we will use the milon/barcod...
Mar-26-2022