0

I want to find records between two dates so I have written this code:

$this->paginate['conditions']['OR']['Clients.date_registered BETWEEN ? and ?'] = [$dateRegFrom, $dateRegTo];

date_registered is a datetime column so I have tried both the formats

i.e date ('Y-m-d') & date ('Y-m-d H:i:s')

This is how the condition looks like,

[OR] => Array
        (
            [Clients.date_registered BETWEEN ? and ?] => Array
                (
                    [0] => 2017-11-01 00:00:00    //2017-11-01 in Y-m-d format
                    [1] => 2018-11-20 22:28:55    //2018-11-20 in Y-m-d format
                )

        )

But I am getting an error(details)

file :     "/vendor/cakephp/cakephp/src/Database/Type/DateTimeType.php"
line : 122
message : "Call to a member function format() on array"

How to get rid of this problem/issue?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
bikash.bilz
  • 821
  • 1
  • 13
  • 33
  • 3
    That syntax isn't supported anymore in CakePHP 3.x, [**use either a query object**](https://book.cakephp.org/3.0/en/controllers/components/pagination.html#using-controller-paginate) with a proper [**between expression**](https://stackoverflow.com/questions/26430259/cakephp-3-0-between-find-condition), or combine `>=` and `<=` conditions. – ndm Nov 20 '18 at 15:04

1 Answers1

1

I have changed my code and used AND condition inside the OR condition,

$this->paginate['conditions']['OR'][] = [
                        'Clients.' . $filter['field'] . ' >=' => $dateRegFrom,
                        'Clients.' . $filter['field'] . ' <=' => $dateRegTo,
                    ];
bikash.bilz
  • 821
  • 1
  • 13
  • 33