Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

Regards

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
155 views
Welcome To Ask or Share your Answers For Others

1 Answer

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
    );
}

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';

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...