Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Eloquent: How to use whereDate with Between?

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

like image 413
Volatil3 Avatar asked Feb 07 '18 06:02

Volatil3


1 Answers

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'
like image 157
Mehravish Temkar Avatar answered Oct 20 '22 14:10

Mehravish Temkar