PHP Laravel 5 Eloquent where between two dates from Database


I will show you example of get records between two dates from database using laravel Eloquent whereBetween method. whereBetween helps to get data between 2 dates from database. here also show you example for retrieve records using where between two columns of database table.

Here i am getting records from users table and get all data of given $start and $end date between records. So you can see following simple example and understand how it is works.

You can also get records from where between two columns. So i give you both example are bellow you can see both example as bellow:

Where Between Two Dates:

$users = User::select("users.*")

->whereBetween('created', ['2018-02-01', '2018-02-10'])

->get();

dd($users);

Where Between Two Columns:

$users = User::select("users.*")

->whereRaw('? between start_date and end_date', [date('Y-m-d')])

->get();

dd($users);

I hope you found best solution.....






March 21, 2018 | 1479 Viewer | Category : PHP Laravel Laravel 5 Laravel 5.5 Laravel 5.6
Related Posts