Laravel has a really nice Carbon date processing package that you could use with your queries. If you want to receive records from the beginning of today, use the Carbon property or use the to get the previous date midnight . startOfDay()
Carbon::yesterday()->endOfDay()
, :
$previousDayMidnight = Carbon::yesterday()->endOfDay();
$currentTime = Carbon::now();
$result = DB::collection('wc_mycollection')->raw(function($collection)
{
return $collection->aggregate(array(
array(
'$match' => array(
'created_at' => array(
'$gte' => $previousDayMidnight,
'$lt' => $currentDateTime
)
)
),
array(
'$group' => array(
'_id' => '$some_id',
'count' => array(
'$sum' => 1
)
)
)
));
});
, MongoDate,
$start = new MongoDate(strtotime(date('Y-m-d H:i:s', '-1 days')));
$end = new MongoDate(strtotime(date('Y-m-d H:i:s')));
$result = DB::collection('wc_mycollection')->raw(function($collection)
{
return $collection->aggregate(array(
array(
'$match' => array(
'created_at' => array(
'$gte' => $start,
'$lt' => $end
)
)
),
array(
'$group' => array(
'_id' => '$some_id',
'count' => array(
'$sum' => 1
)
)
)
));
});