DEV Community

Techsolutionstuff
Techsolutionstuff

Posted on • Originally published at techsolutionstuff.com

Laravel whereDate and whereDay Example

In this tutorial, we will see laravel whereDate and whereDay example. As you all know laravel provides many inbuilt functionalities like query builder, eloquent, etc. So, here we will give you examples of whereDay and WhereDate using the date function in laravel 8.

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

So, Let's see laravel whereDate and whereDay example, date function in laravel 8 also you can use whereDate and whereDay functions in laravel 6, laravel 7 and laravel 8.
WhereDate()

Example :

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

In this example, you will get all results of bday which has a date like 06-02-2022.

Example :

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

Read Also : Laravel whereHas and orWhereHas Query Example


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', '2022-02-06')
            ->get();
dd($birthdate);
Enter fullscreen mode Exit fullscreen mode

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


You might also like :

Oldest comments (0)