10

I am using Laravel 5.5, I need to form a query where only date part of a datetime column should be matched, equivalent of date(date_col)='2018-01-01' kind of thing. How do I achieve this in Eloquent way? WhereDate() returns date part but is there some way to merge both?

Thanks

2 Answers 2

29

For merging whereDate and between you can use something like this:

User::whereBetween(DB::raw('DATE(created_at)'), array($from_date, $to_date))->get();

sql :

select * from `users` where DATE(created_at) between '2018-02-01' and '2018-02-06'
Sign up to request clarification or add additional context in comments.

1 Comment

this is the right answer for whereBetween
0

You can use Carbon:

$q->whereDate('date_col', '=', Carbon::parse($date)->toDateString());

whereDate should work too, pass in the value as the 2nd parameter

->whereDate('date_col', '2018-02-06')

1 Comment

That was not my original question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.