In this post, We will see Laravel query builder methods. I will explain how to use Laravel whereDate() and whereDay().
Let?s start with how to use whereDate() and whereDay() Laravel Query Builder methods.
Below we will see one by one method with example and understand the how this two Laravel query builder functions works.
This is the short guide of whereDate() and whereDay() Laravel Query Builder methods.
whereDate() Example
Now, we will see how to use whereDate() example.
1. Example 1
Let?s take and example of Employee table, we need to find the list of employee who joined on 2021-10-01 this particular date, for that we need to use whereDate() methods, below example will give you the demonstration.
$employeeLists = DB::table('employee')
->whereDate('joining_date', '2021-10-01')
->get();
In the above example, you will get all employee who joined on 2021-10-01.
2. Example 2
Now we will take second example of whereDate() methods, In the second example we will find the list of employee who joined in 2021 year.
$employeeLists = DB::table('employee')
->whereDate('joining_date', '>=','2021-01-01')
->get();
In the above example, you will get all employee who joined in 2021 year.
whereDay() Example
Now, we will see how to use whereDay() example.
We will use same employee table for this method also, if we want to find the list of employee who joined on 01 first day of every month then we have to use whereDay() method.
Below example will give the demonstration.
$employeeLists = DB::table('employee')
->whereDay('joining_date', '01')
->get();
I hope you will like the content and it will help you to learn Laravel whereDate and whereDay Example
If you like this content, do share.