cakephp - Find within date range -
i'm trying find services each customer in monthly date range. following answered question cakephp: date range created code in summaries controller:
public function view($id=null) { //other code $this->loadmodel('event'); $summary = $this->summary->find('first', array('conditions' => array('summary.id' => $id))); $first = date('m-01-y', strtotime($summary['summary']['date'])); //added debugging , value date want $this->set('first', $first); $last = date('m-t-y', strtotime($summary['summary']['date'])); //debugging, works $this->set('last', $last); $conditions = array("'event.start' >=" => $first, "'event.start' <=" => $last, 'event.customer_id' => 'summary.customer_id' ); $this->set('events', $this->event->find('all', array('conditions' => $conditions)));
but $events variable in view empty. tried eliminate customer_id condition test date ranges, , problem seems 'event.start' not compared properly. , date() function can't used inside quotes. hints?
you adding more single quote query not work
please change below $conditions
$conditions = array("event.start >=" => "'".$first."'", "event.start <=" => "'".$last."'", 'event.customer_id' => 'summary.customer_id' );
please let me know if can more
$summary['summary']['date'] = '4-5-2013'; // format 'd-m-y'; $first = date('m-01-y h:i:s', strtotime($summary['summary']['date'])); echo "first".$first; echo "<br>date -> ". date('m-t-y');
output like
first05-01-2013 00:00:00 date -> 05-31-2013
so can compare date
Comments
Post a Comment