Last active
December 28, 2015 20:19
-
-
Save mgng/7556531 to your computer and use it in GitHub Desktop.
mongodb で 日付範囲検索する場合
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$startDate ="2013-11-12 00:00:00"; | |
$endDate = "2013-11-13 00:00:00"; | |
// mongodb内部でISODate Objectで保存されている場合は MongoDate 使って変換する必要がある | |
$query = array("insert_date" => array( | |
'$lt' => new MongoDate(strtotime($endDate)), | |
'$gte' => new MongoDate(strtotime($startDate)) | |
)); | |
$cursor = $collection->find( $query ); | |
$result = iterator_to_array( $cursor, false ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment