Udhayan Nair
Udhayan Nair

Reputation: 470

changing sql statement to eloquent query

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

Answers (2)

Khalid Khan
Khalid Khan

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

Adrian Edy Pratama
Adrian Edy Pratama

Reputation: 4051

You can try this :

$yourQuery->whereBetween('created_at', ['20190601', '20190630']);

Read more at whereBetween section in here

Upvotes: 4

Related Questions