dqwr32867 2018-11-01 12:16
浏览 30

从两个日期之间的数据库差异中检索内部数据

I have a table named TestingLogDevice. Table column name dateee. Table dateee field value looks like this.

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

I have a form looks like this. When I submit this form value. Then I get this value looks like this

![Form Image

Array
(
    [precise_chart_val] => Array
        (
            [id] => 
            [start_date] => 30-10-18
            [end_date] => 01-11-18
        )

)

I retrieve the value two date difference from table TestingLogDevice using this code. I follow this link 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')
         )
    )
);

But when I print datas I get all value of dateee field from id 1 to 15. But I get only data from id 1 to 11. Where I'm wrong? I don't fix it.

  • 写回答

1条回答 默认 最新

  • douhao6557 2018-11-02 05:27
    关注

    my dateee field is vachar.

    You are getting this result because of your dateee field datatype. To solve this problem Either change data type from varchar to datetime

    OR

    Change

    $conditions  = array('TestingLogDevice.dateee BETWEEN ? and ?' => array($start_date, $end_date));
    

    To

     $conditions  = array("date_format(str_to_date(TestingLogDevice.dateee, '%d-%m-%Y'), '%d-%m-%Y') BETWEEN ? and ?" => array($start_date, $end_date));
    

    mySQL convert varchar to date

    评论

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能