PHP的parse.com parseQuery之间createdAt [英] php parse.com parseQuery between createdAt
问题描述
我将PHP库用于parse.com,并且我想在两个日期之间进行过滤(与CreatedAt字段进行比较),我试图使用:
I using the PHP library for parse.com and I wanna do a filter between two dates compared with CreatedAt field, I'm trying to use:
$pqry->whereGreaterThanOrEqualTo('createdAt', $pqry->dataType('date', $startdate)) ;
$pqry->whereLessThanOrEqualTo('createdAt', $pqry->dataType('date', $enddate)) ;
//$startdate = '2014/07/21 00:00:00'; $endtdate = '2014/07/21 23:59:59';
但是不起作用,我找到了以下代码:
but don't work, i found this code:
public function whereBetweenOrEqualDates($key, $startDate, $endDate){
if(isset($key) && isset($startDate) && isset($endDate)){
$this->_query[$key] = array(
'$gte' => $startDate,
'$lte' => $endDate
);
}
但是效果不好,有人可以告诉我执行此过滤器的最佳方法吗?
But don't work well, some one can tell me the best way to do this filter?
致谢
推荐答案
因为它可以帮助任何人,所以代码:
as it helps anyone, the code:
public function whereBetweenOrEqualDates($key, $startDate, $endDate){
if(isset($key) && isset($startDate) && isset($endDate)){
$this->_query[$key] = array(
'$gte' => $startDate,
'$lte' => $endDate
);
}
对于过滤器之间的效果很好,日期格式需要以ISO格式发送,例如:
Works fine for between filter, the format for the date need send in a ISO, like:
//$startdate = '2014-07-21T00:00:00Z-6'; $endtdate = '2014-07-21T23:59:59Z-6';
Z-6是我的时区,parse.com的默认值是Z0,那么您需要使用这种格式保存日期并以这种格式请求,这样就解决了我的问题.
The Z-6 is my timezone, the parse.com default is Z0 then you need save your dates with this format and request with this format to, this solved my problem.
这篇关于PHP的parse.com parseQuery之间createdAt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!