Reputation: 470
So I have an SQL statement as such;
AND created_at BETWEEN '20190601' and '20190630'
How do I change this to an eloquent query? Or is it better to just use a db:raw query?
All inputs are very much appreciated. Cheers!
Upvotes: 0
Views: 57
Reputation: 3185
As you are comparing dates, then do this:
$fromDate = '20190601';
$toDate = '20190630';
$yourquery->whereBetween('created_at', array($fromDate->toDateTimeString(), $toDate->toDateTimeString()) )->get();
Upvotes: 2
Reputation: 4051
You can try this :
$yourQuery->whereBetween('created_at', ['20190601', '20190630']);
Read more at whereBetween section in here
Upvotes: 4