0
SELECT count(*) FROM payments WHERE status='Success' and createddate BETWEEN '2020-05-05' AND '2020-05-06'

$numcount= TableRegistry::get('Payments')->find('all', array(
    'conditions' => array('status'=>'Success','and' => array(
    array('createddate <= ' => $date1,
        'createddate >= ' => $date2
    )
))))->count();

Please help. Thanks in advance. I tried but the code doesn't work.

5
  • 1
    What does "doesn't work" mean? Is your createddate field just a date, or does it have the time in it too? Commented May 6, 2020 at 17:58
  • if i execute this query showing zero always. and createddate have date only Commented May 7, 2020 at 0:33
  • $date1 is which date? Commented May 7, 2020 at 0:41
  • yes $date1='2020-05-05' and $date2='2020-05-06' eg. SELECT count(*) FROM payments WHERE status='Success' and createddate BETWEEN $date1 AND $date2 Commented May 7, 2020 at 0:45
  • So, "between 2020-05-05 and 2020-05-06" means "greater than or equal to 2020-05-05 and less than or equal to 2020-05-06". You've got them the other way around. There's no date less than or equal to the 5th and also greater than or equal to the 6th. Commented May 7, 2020 at 0:50

1 Answer 1

1

You've got your dates backwards. Also, you don't need an extra 'AND' in your conditions, they're all AND by default.

$numcount= TableRegistry::get('Payments')->find('all', array(
    'conditions' => array(
        'status' => 'Success',
        'createddate >=' => $date1,
        'createddate <=' => $date2
    )
))->count();
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.