Home > Mobile >  Laravel eloquent where TIMESTAMP time is specific hour
Laravel eloquent where TIMESTAMP time is specific hour

Time:10-07

I want to check after my orWhereColumn if planned_completion_date time is at 09:00. planned_completion_date is of timestamp datatype. How can I check this? This is how my query looks like:

$portings = Porting::with('items')
->where('status', AbstractPorting::STATUS_ACCEPTED)
->where(function ($q) {
  $q->where('planned_completion_date', '<=', date("Y-m-d H:i:s", time()));
  $q->orWhereColumn('planned_completion_date', '<', 'first_possible_date');
})->get();

CodePudding user response:

You can try this :

$portings = Porting::with('items')
->where('status', AbstractPorting::STATUS_ACCEPTED)
->where(function ($q) {
  $q->where('planned_completion_date', '<=', date("Y-m-d H:i:s", time()));
  $q->orWhereColumn('planned_completion_date', '<', 'first_possible_date');
  $q->where(DB::raw("DATE_FORMAT(planned_completion_date, '%H:%i')"), '=', '09:00');
})->get();
  • Related