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.....
Do you like below Tutorials ?
- Laravel 5.6 - Collection could not be converted to int
- Laravel - How to generate secure https URL from route?
- Laravel - Vue JS File Upload Example
- How to get last 7 days data in Laravel?
- Laravel Validation required if other field empty example
- Laravel Eloquent - When Case Statement in Select Query Example
- Laravel 7.x and 6.x Passing Variable to Javascript Example
- How to pass PHP variables in JavaScript or jQuery?