【问题标题】:Mongodb ISODate format comparison not working in PHPMongodb ISODate 格式比较在 PHP 中不起作用
【发布时间】:2016-06-14 07:22:54
【问题描述】:

我有一个像"estdate" : "2016-06-14T06:49:00.000Z"这样的mongodb记录
我正在编写以下php代码来查询时间

$from=$start = new MongoDate(strtotime('2016-04-11 00:00:00'));
 $to=new MongoDate(strtotime('2016-06-18 00:00:00'));
 $filterpatient = array("order.patientinfo.order_id" => $ordertext,"order.orderitem.estdate" => array('$gte' =>$from, '$lte' => $to));
 $cursor = $collection->find($filterpatient)->sort(array('_id'=>-1)); 

但这没有给出任何结果。

【问题讨论】:

    标签: php mongodb mongodb-query


    【解决方案1】:

    如果您使用的是 mongodb 驱动程序,这可能对您有所帮助。

    $starttime = strtotime("2016-04-11 00:00:00"); $utcstartdatetime = new MongoDB\BSON\UTCDateTime($starttime);

    现在在您的查询中使用 $utcstartdatetime 作为时间。

    【讨论】:

    • 想法不错但结果不是,strtotime 返回MongoDB\BSON\UTCDateTime 需要毫秒时的秒数(也称为 UNIX 时间戳),只需乘以 1000
    猜你喜欢
    • 2013-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多