我有一个名为TestingLogDevice
的表。表列名称dateee
。
表dateee
的字段值如下所示。
id dateee
1 01-11-18
2 01-11-18
3 01-11-18
4 01-11-18
5 31-11-18
6 31-11-18
7 31-11-18
8 31-11-18
9 31-11-18
10 30-11-18
11 30-11-18
12 29-11-18
13 28-11-18
14 28-11-18
15 27-10-18
我有一个看起来像这样的表格。当我提交此表单值时。然后我得到的值看起来像这样
Array
(
[precise_chart_val] => Array
(
[id] =>
[start_date] => 30-10-18
[end_date] => 01-11-18
)
)
我使用此代码从表TestingLogDevice
中检索值两个日期差。我点击此链接
Tutorial Link
$start_date = $data['precise_chart_val']['start_date'];
$end_date = $data['precise_chart_val']['end_date'];
$conditions = array('TestingLogDevice.dateee BETWEEN ? and ?' => array($start_date, $end_date));
$this->set('datas',
$this->TestingLogDevice->find('all',
array(
'conditions' =>array($conditions, 'TestingLogDevice.Siteid'=>$testing_log_device_site_name),
'order' => array('id' => 'desc')
)
)
);
但是当我打印datas
时,我得到的dateee
字段的所有值都从id 1到15 。但是我只能从ID 1到11获得数据。哪里错了?我不解决。
答案 0 :(得分:0)
我的约会对象字段为vachar。
由于日期对象字段数据类型,您将得到此结果。解决此问题的方法之一是将数据类型从varchar更改为datetime
OR
更改
$conditions = array('TestingLogDevice.dateee BETWEEN ? and ?' => array($start_date, $end_date));
收件人
$conditions = array("date_format(str_to_date(TestingLogDevice.dateee, '%d-%m-%Y'), '%d-%m-%Y') BETWEEN ? and ?" => array($start_date, $end_date));