Are there any way to get difference of two days (today & created_at) using laravel query?
I have tried as follows.but that didn’t work for me
public function scopeActivatedOrders($query,$currentDate){ return $query->select('*') ->where('orders.activated', '=', '1') ->where('DATEDIFF(order.arrived_date,$currentDate)','>','14')->get(); }
Thank you!
Advertisement
Answer
the problem in your code is that you are using standard where that take a column as the first parameter not an expression … you can use whereRaw, or just using DB::raw like:
return $query->select('*') ->where('orders.activated', '=', '1') ->whereRaw('DATEDIFF(order.arrived_date,Now())>14')->get();
note: you can mysql now() function instead of $currentDate variable …