如何在php报告中应用日期过滤器

如何在php报告中应用日期过滤器,php,cakephp,cakephp-3.0,Php,Cakephp,Cakephp 3.0,如何应用日期范围筛选器以获取精确日期行 下面是我的sql表 id name created 1 abc 2018-07-06 10:30:45 2 test 2018-07-01 10:30:45 3 raj 2018-07-05 10:30:45 4 zyz 2018-07-08 10:30:45 但当我选择日期2018/07/01-2018/07/01时,它返回空行 当我选择日期2018/07/01-2018/07/02时,它将显示在下面的

如何应用日期范围筛选器以获取精确日期行

下面是我的sql表

id  name     created
1   abc   2018-07-06 10:30:45 
2   test  2018-07-01 10:30:45  
3   raj   2018-07-05 10:30:45  
4   zyz   2018-07-08 10:30:45
但当我选择日期2018/07/01-2018/07/01时,它返回空行

当我选择日期2018/07/01-2018/07/02时,它将显示在下面的单行中

2   test  2018-07-01 10:30:45 
我的问题是,如果我需要“开始日期”和“结束日期”范围筛选器中所选日期的记录,如何应用日期筛选器

下面是我的php代码

public function clientReport(){
        if ($this->request->is('post')) {
            $daterng = $this->request->data['daterange'];
            if(!empty($daterng)){
                $dates = explode("-", $daterng);
                $frmDate =  date("Y-m-d", strtotime($dates[0]));
                $toDate =  date("Y-m-d", strtotime($dates[1]));
            } 
            $conditions = [];
            if(!empty($frmDate)){
                $conditions['Orders.created >='] = $frmDate;
            }
            if(!empty($toDate)){
                $conditions['Orders.created <='] = $toDate;
            }
            $orders = $order
            ->find() 
            ->where($conditions);            
            $orders->enableHydration(false);  //  You can retrieve basic arrays by disabling hydration 
            if(!empty($orders)){
              $this->set('clientlist', $orders);
            }

        }        
    }
公共函数clientReport(){
如果($this->request->is('post')){
$daterng=$this->request->data['daterange'];
如果(!空($daterng)){
$dates=分解(“-”,$daterng);
$frmDate=日期(“Y-m-d”,标准时间($dates[0]);
$toDate=日期(“Y-m-d”,标准时间($dates[1]);
} 
$conditions=[];
如果(!空($frmDate)){
$conditions['Orders.created>=']=$frmDate;
}
如果(!空($toDate)){

$conditions['Orders.created您还必须在查询中添加时间

       if(!empty($frmDate)){
            $conditions['Orders.created >='] = $frmDate.' 00:00:00';
        }
        if(!empty($toDate)){
            $conditions['Orders.created <='] = $toDate.' 23:59:59';
        }
if(!empty($frmDate)){
$conditions['Orders.created>=']=$frmDate'00:00:00';
}
如果(!空($toDate)){

$conditions['Orders.created要根据日期范围筛选数据库,可以使用

SELECT * FROM your_table WHERE DATE(created) BETWEEN '2018-07-01' AND '2018-07-01'

你需要“围捕”结束日期为23:59:59小时。实际上,您正在使用时间戳,因此日期将转换为日期/时间。2018/07/01可能会变成当天的午夜00:00:00。当从2018/07/01到2018/07/01进行搜索时,您实际需要的是从2018/07/01 00:00到2018/07/01 23:59:59进行搜索。

但我希望获得基于da的所有行仅限日期。如果日期匹配,那么它将得到如何操作???我也尝试了$frmDate=date(“Y-m-d 00:00:00”,strottime($dates[0]);$toDate=date(“Y-m-d 00:00:00”,strottime($dates[1]);但不工作将
$toDate=date(“Y-m-d 00:00:00”,strottime($dates[1])
更改为
$toDate日期(“Y-m-d 23:59:59”,strotime($dates[1])
正确地检查我的答案,但我要问的是如何动态地实现它,因为给定的mysql数据只是一个例子。我在mt表中有很多行,每行有不同的时间。因此如何仅基于日期获取。它是动态的。唯一的时间是固定的(从开始一天开始到最后一天结束)但是如何在cakephp中使用between,findI认为应该是这样的:->where(“DATE(created)between”,$frmDate.”和“$toDate”);不是100%确定,因为我没有使用过cakePHP,这可能会有一些帮助:但我只想基于日期获取所有行。如果日期匹配,那么它将得到,然后如何实现???bcoz我也尝试了$frmDate=date(“Y-m-d 00:00:00”,strottime($dates[0]);$toDate=date(“Y-m-d 00:00:00”,strottime($dates[1]));但不起作用仅基于日期获取数据..你能给我看一下SQL查询吗?是的,请更新我的查询