Php 使用RejectionDB during()检索最近7天
在过去的7天里,我已经尝试了几个小时,使用RejectionDB和PHP返回所有结果 在查看文档时,我发现最合适的REJECTDB函数应该是Php 使用RejectionDB during()检索最近7天,php,rethinkdb,Php,Rethinkdb,在过去的7天里,我已经尝试了几个小时,使用RejectionDB和PHP返回所有结果 在查看文档时,我发现最合适的REJECTDB函数应该是during() 下面是我的代码,我已经意识到这项任务远比表面上看起来困难。我曾尝试在期间将PHP中的DateTime直接用于,但也没有成功 $sevenago = new DateTime('7 days ago'); $sevenago->setTimeZone(new DateTimeZone('Asia/Kolkata')); $sevenag
during()
下面是我的代码,我已经意识到这项任务远比表面上看起来困难。我曾尝试在期间将PHP中的DateTime
直接用于,但也没有成功
$sevenago = new DateTime('7 days ago');
$sevenago->setTimeZone(new DateTimeZone('Asia/Kolkata'));
$sevenago = date_format($sevenago, 'U');
$now = new DateTime();
$now->setTimeZone(new DateTimeZone('Asia/Kolkata'));
$now = date_format($now, 'U');
$ordersLastWeek = r\table("orders")->filter(function($doc) {
return $doc('status')->eq('shipped')
->rAnd($doc('time')->during(r\epochTime($sevenago), r\epochTime($now)));
})->run($conn);
time
字段存储如下(标准日期时间类型):
任何帮助都将不胜感激
$ordersLastWeek = r\table("orders")->filter(function($doc) {
return $doc('status')->eq('shipped')
->rAnd(($doc('time') > r\epoch_time($sevenago)));
})->run($conn);
你试过这个吗。希望它能起作用。试试这个:
$ordersLastWeek = r\table("orders")->filter(function($doc) use ($sevenago, $now) {
return $doc('status')->eq('shipped')->rAnd($doc('time')->during(r\epochTime($sevenago), r\epochTime($now)));
})->run($conn);
在您的代码中,您忘记使用过滤函数的用法($sevenago,$now)
。不幸的是,这不起作用。我尝试了r\epochTime
,但也注意到r\epochTime
在PHP RQL.Wow中是一个未定义的函数。晚上太晚了。很好,你说得对,我确实忘了设置那些变量。我们也可以忽略epochTime
,因为我们现在可以直接从PHP使用DateTime
-
$ordersLastWeek = r\table("orders")->filter(function($doc) use ($sevenago, $now) {
return $doc('status')->eq('shipped')->rAnd($doc('time')->during(r\epochTime($sevenago), r\epochTime($now)));
})->run($conn);