2
where concat(`year`,'-',`month`)  BETWEEN '2013-02'  AND '2013-03';

how to use this query in cake php's custom query pagination like this way..

$conditions = array('concat('Payroll.year','-','Payroll.month')  BETWEEN ? and ?' => array(2013-02, 2013-03));

$staff_list =  $this->Payroll->find("all", array("fields" => array("Payroll.id", "Payroll.month", "Payroll.year"),"conditions"=>$conditions));

thank you.

6
  • You did not specify your cakephp version. In cake 2.x you would probably use virtual fields here. Commented Mar 28, 2013 at 10:07
  • Is it possible to use the virtual field name in the where condition apart frm the table fields.. Commented Mar 28, 2013 at 10:17
  • Yes, that is possible. Commented Mar 28, 2013 at 10:31
  • thanks for ur nice reply.... Commented Mar 28, 2013 at 10:37
  • 1
    $conditions = array('monthyear BETWEEN ? and ?' => array(2013-2, 2013-3)); here monthyear is virtual Commented Mar 28, 2013 at 10:38

1 Answer 1

2

yes, you could do: in you model:

var $virtualFields = array(
    'payroll_date' => 'CONCAT(Payroll.year, " ", Payroll.month)'
);

and in controller:

$staff_list =  $this->Payroll->find("all", array(
  "fields" => array("Payroll.id", "Payroll.month", "Payroll.year"),
  "conditions" => array('Payroll.payroll_date BETWEEN ? AND ?' => array('2013-02', '2013-03'))
));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.