i tried but i seem to fail to implement it can you explain how? the whereBetween expects an array of dates that i already have which in my case is part of the record that i want to retrieve...
kunalthool said:
use whereBetween
Are your operators the right way round?
->where('period_starts_at','<=',$dt)
->where('period_ends_at','>=',$dt)
->first();
Oh i got the error you cant get the results.
No here is the solution
public function current(){ $from = date('Y-m-d' . '00:00:00', time()); $to = date('Y-m-d' . '24:60:60', time());
$current = Connection::
where('user_id',$this->user_id)
->where('status','active')
->whereBetween('created_at', array($from, $to))->first();
return $current; }
public function current(){
$from = date('Y-m-d' . ' 00:00:00', time()); //need a space after dates.
$to = date('Y-m-d' . ' 24:60:60', time());
$current = Connection::
where('user_id',$this->user_id)
->where('status','active')
->whereBetween('created_at', array($from, $to))->first();
return $current;
}
Thanks for this - Just to chime in for people using Carbon - make sure you use the toDateTimeString
method.
$fromDate = new Carbon('last week');
$toDate = new Carbon('now');
POST::whereBetween('created_at', array($fromDate->toDateTimeString(), $toDate->toDateTimeString()) )->get();
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community