如何使用php查询mongodb日期

如何使用php查询mongodb日期,php,mongodb,Php,Mongodb,我需要将这个查询从php转换为mongoDB查询 $query = "select * from table where data_added like '%data%'; 我把日期存储在变量中 $date = "2013-09-02"; 在我的mongo文档中,日期排序为: $dateAdded = new MongoDate(strtotime('2013-09-02 12:21:55')); 我试过了 $date = new MongoDate(strtotime("$date"))

我需要将这个查询从php转换为mongoDB查询

$query = "select * from table where data_added like '%data%';
我把日期存储在变量中

$date = "2013-09-02";
在我的mongo文档中,日期排序为:

$dateAdded = new MongoDate(strtotime('2013-09-02 12:21:55'));
我试过了

$date = new MongoDate(strtotime("$date"));

$mongo->find(array('date_added'=>array('$lt'=>$date)));

and 
$mongo->find(array('date_added'=>$date));
但是没有成功

所以我需要查询usin(Y-m-d)而不是(Y-m-d h:I:s) 那么如何在mongo中使用LIKE查询数据呢


谢谢

您需要进行范围查询。创建一个时间戳,例如使用strotime(),在一天开始时获取unix时间戳,在一天结束时获取另一个时间戳

根据您希望这两个端点是包含的还是独占的,您可以使用

// Both points/seconds inclusive
->find(array("date" => array('$gte' => $startOfDay, '$lte' => $endOfDay)));
// Both seconds exclusive
->find(array("date" => array('$gt' => $startOfDay, '$lt' => $endOfDay)));

参见

How-about
$dateAdded=new MongoDate(日期('Y-m-d',标准时间('2013-09-02 12:21:55'))?谢谢,但我需要$dateAdded=newmongodate(日期('Y-m-d',strotime('2013-09-02'));它已经是
Y-m-d
格式。我不太确定你想做什么,但它有我需要的(h:I:s),没有(h:I:s),MongoDB中的数据类型是什么?您可能需要执行一个范围,
2013-09-22 00:00:00
2013-09-22 23:59:59