DEV Community

loading...

Laravel whereDate and whereDay Example

Websolutionstuff
I am Laravel Developer. I have good knowledge of JavaScript, JQuery, Bootstrap and REST API.
Originally published at websolutionstuff.com ・1 min read

In this small tutorial we will see laravel whereDate and whereDay example, as you all know laravel provide many inbuilt functionalities like query builder, eloquent etc.

So, here i will give you example of whereDay and WhereDate using date function in laravel 8.

The whereDate method is used to compare a column's value against a date. whereDate() through we can make condition like date even column datatype timestamps.

WhereDate()

Example-1 :

$birthdate = DB::table('students')
            ->whereDate('bday', '2021-01-01')
            ->get();
dd($birthdate);
Enter fullscreen mode Exit fullscreen mode

In this example you will get all result of bday which one have date like 01-01-2021.

Example-2 :

$birthdate = DB::table('students')
            ->whereDate('bday','<=','2021-01-01')
            ->get();
dd($birthdate);
Enter fullscreen mode Exit fullscreen mode

whereDay()

The whereDay method is used to compare a column's value against a specific day of the month, whereDay() through we can get only specific day records from your timestamps column.

Example:

$birthdate = DB::table('students')
            ->whereDay('bday', '2021-01-01')
            ->get();
dd($birthdate);
Enter fullscreen mode Exit fullscreen mode

In this example you will get all data which one date day value has 01.


Read More : Change Date Format Using Carbon In Laravel

Read More : How To Create Custom Middleware In Laravel

Read More : How To Validate Max File Size Using JavaScript

Thanks for the reading...!!
Don't forgot to like, share and comment.

Discussion (0)