我需要将这个PHP查询转换为MongoDB查询。
在我的Mongo文档中,日期排序如下:
$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));
但是一直没有成功。
所以我需要使用(Y-m-d)而不是(Y-m-d h:i:s)来查询数据,那么如何在Mongo中使用LIKE查询呢?
谢谢。
$dateAdded = new MongoDate(date('Y-m-d',strtotime('2013-09-02 12:21:55')));
? - Amal MuraliY-m-d
格式了。我不确定你想做什么。 - Amal MuraliMongoDate
),但是该行首先将您的日期字符串转换为Unix时间戳,然后使用date()
将其格式化为Y-m-d
格式。 - Amal Murali2013-09-22 00:00:00
到2013-09-22 23:59:59
。 - WiredPrairie