Selecting date NOT NULL records between a specific range with Propel

Posted by Jon Winstanley on Stack Overflow See other posts from Stack Overflow or by Jon Winstanley
Published on 2010-05-04T23:44:16Z Indexed on 2010/05/04 23:48 UTC
Read the original article Hit count: 238

Filed under:
|
|

Using Propel I would like to find records which have a date field which is not null and also between a specific range.

However, Propel seems to overwrite the criteria with the NOTNULL criteria.

Is it possible to do this?

  //create the date ranges
  $start_date = mktime(0, 0, 0, date("m")  , date("d")+$start, date("Y"));
  $end_date = mktime(0, 0, 0, date("m")  , date("d")+$end, date("Y"));

  //add the start of the range
  $c1 = $c->getNewCriterion(TaskPeer::DUE_DATE, null);
  $c1->addAnd($c->getNewCriterion(TaskPeer::DUE_DATE, $end_date, Criteria::LESS_EQUAL));
  $c->add($c1);

  //add the end of the range
  $c2 = $c->getNewCriterion(TaskPeer::DUE_DATE, null);
  $c2->addAnd($c->getNewCriterion(TaskPeer::DUE_DATE, $start_date, Criteria::GREATER_EQUAL));
  $c->add($c2);

  //remove the null entries
  $c3 = $c->getNewCriterion(TaskPeer::DUE_DATE, null);
  $c3->addAnd($c->getNewCriterion(TaskPeer::DUE_DATE, null, Criteria::ISNULL));
  $c->add($c3);

© Stack Overflow or respective owner

Related posts about propel

Related posts about date-range