Reputation: 2763
I need to get the records that is created from yesterday at 5.00PM
until now
so if I try the following:
8am
query start yesterday 5pm
until now
(8am) 1pm
query start yesterday 5pm
until now
(1pm)... and so on
Here is my function.
public function allNewOrdersToday() {
$allNewOrders = ( new OrderList() )
->where( 'created_at', '>=', Carbon::yesterday() )
return $allNewOrders;
}
Upvotes: 1
Views: 6033
Reputation: 4202
Using Carbon
, you should be able to query where the date is beyond Yesturday 5:00pm
using the yesturday()
and setTime()
carbon methods:
use Carbon\Carbon;
...
public function allNewOrdersToday() {
return OrderList::whereDate('created_at', '>=', Carbon::yesterday()->setTime(17, 00, 00)->toDateTimeString())
->get();
}
In this example, I have changed (new OrderList())
to OrderList::...
as you are using eloquent
models and are able to call query builder methods without needing a new instance of the class.
Upvotes: 3
Reputation: 199
Try to do like this:
public function allNewOrdersToday() {
$allNewOrders = ( new OrderList() )
->whereDate( 'created_at', '>=', date('Y-m-d 17:00:00',strtotime("-1 days"))
return $allNewOrders;
}
Upvotes: 1