我想查找两个日期之间的记录,所以我编写了这段代码:
$this->paginate['conditions']['OR']['Clients.date_registered BETWEEN ? and ?'] = [$dateRegFrom, $dateRegTo];
date_registered
是datetime
列,所以我尝试了两种格式
即日期('Y-m-d')和日期('Y-m-d H:i:s')
条件就是这样,
[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
)
)
但是我收到一个错误(详细信息)
file : "/vendor/cakephp/cakephp/src/Database/Type/DateTimeType.php"
line : 122
message : "Call to a member function format() on array"
如何摆脱这个问题/问题?
答案 0 :(得分:0)
我已更改代码,并在AND
条件中使用了OR
条件,
$this->paginate['conditions']['OR'][] = [
'Clients.' . $filter['field'] . ' >=' => $dateRegFrom,
'Clients.' . $filter['field'] . ' <=' => $dateRegTo,
];