Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

whereBetween Dates in laravel 4 eloquent

I have a query like that

SELECT * FROM `sp_price` WHERE (`from_date` between '2014-08-15' and '2014-09-18') || (`to_date` between '2014-08-15' and '2014-09-18')

Now how I can convert this query in laravel 4. I use Eloquent

like image 992
Md. Sahadat Hossain Avatar asked Sep 28 '14 05:09

Md. Sahadat Hossain


People also ask

How do I get this week records in Laravel?

Get Current Week Data in Laravel Using the below Laravel eloquent query for fetching the current week data from the MySQL database table. $current_week = User::whereBetween('created_at', [Carbon::now()->startOfWeek(), Carbon::now()->endOfWeek()])->get();


2 Answers

DB::table(sp_price)
     ->whereBetween('from_date',array('2014-08-15','2014-08-18'))
     ->orWhereBetween('to_date',array('2014-08-15','2014-08-15'))
     ->get();

maybe you can try this

like image 135
tigerDisplayName Avatar answered Oct 25 '22 00:10

tigerDisplayName


  $count =  TokenLog::whereBetween(DB::raw('date(created_at)'), [$start_date, $end_date])->get();
like image 43
Godfrey Makori Avatar answered Oct 25 '22 00:10

Godfrey Makori