2017-05-16 6 views
0

私はcreatedDatecreatedDateY-m-d H:i:sという形式のdatetime値を含むmongo dbコレクションを持っています。 私は日付(Y-m-d)だけ知っている方法でコレクションを検索する方法はありますか?私はいくつかの解決策を試しましたが、私にとっては何も効果がありませんでした。助けてくれてありがとう!最後に自分で解決mongo dbで日付を検索

$currentDate = '2017-05-16'; 
$dateQuery = ['createdDate' => $currentDate]; 

foreach ($this->collection->find($dateQuery) as $key => $log) { 
    ..... 
} 

答えて

0

$dateRegex = new \MongoRegex(('/' . $currentDate . '/i')); 

    foreach ($this->collection->find(['createdDate' => $dateRegex]) as $key => $log) { 
     .... 
    }