首页 > 代码库 > php 打印今天,昨天,本周,上周,当月,上月,本季,上季,今年,去年数据

php 打印今天,昨天,本周,上周,当月,上月,本季,上季,今年,去年数据

if($filter[‘mode‘]) {
            
            switch ($filter[‘mode‘]) {
                case 1://今天的数据
                    $time_start     = date("Y-m-d H:i:s",mktime(0, 0 , 0, date(‘m‘),date(‘d‘),date("Y")));
                    $time_end       = date("Y-m-d H:i:s",mktime(23,59,59,date(‘m‘),date(‘d‘),date("Y")));
                    $ex_where .= ‘ and dt >= ‘ . strtotime($time_start) . ‘ and dt <= ‘ . strtotime($time_end);
                    break;
                case 2://昨天的数据
                    $time_start     = date("Y-m-d H:i:s",mktime(0, 0 , 0, date(‘m‘),date(‘d‘),date("Y")));
                    $time_end       = date("Y-m-d H:i:s",mktime(23,59,59,date(‘m‘),date(‘d‘),date("Y")));
                    $ex_where .= ‘ and dt >= ‘ . strtotime($time_start) . ‘ and dt <= ‘ . strtotime($time_end);
                    break;
                case 3://本周的数据
                    $time_start     = date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("w")+1,date("Y")));                    
                    $time_end       = date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+7,date("Y")));
                    $ex_where .= ‘ and dt >= ‘ . strtotime($time_start) . ‘ and dt <= ‘ . strtotime($time_end);
                    break;
                case 4://上周的数据
                    $time_start     = date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("w")+6,date("Y")));                    
                    $time_end       = date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w"),date("Y")));
                    $ex_where .= ‘ and dt >= ‘ . strtotime($time_start) . ‘ and dt <= ‘ . strtotime($time_end);
                    break;
                case 5://当月的数据
                    $time_start     = date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),1,date("Y")));                    
                    $time_end       = date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("t"),date("Y")));
                    $ex_where .= ‘ and dt >= ‘ . strtotime($time_start) . ‘ and dt <= ‘ . strtotime($time_end);
                    break;
                case 6://上月的数据
                    $time_start     = date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m") -1,1,date("Y")));                    
                    $time_end       = date("Y-m-d H:i:s",mktime(23,59,59,date("m"),0,date("Y")));
                    $ex_where .= ‘ and dt >= ‘ . strtotime($time_start) . ‘ and dt <= ‘ . strtotime($time_end);
                    break;
                case 7://本季的数据
                    $season = ceil((date(‘n‘))/3);//当月是第几季度 
                    $time_start     = date(‘Y-m-d H:i:s‘, mktime(0, 0, 0,$season*3-3+1,1,date(‘Y‘)));                    
                    $time_end       = date(‘Y-m-d H:i:s‘, mktime(23,59,59,$season*3,date(‘t‘,mktime(0, 0 , 0,$season*3,1,date("Y"))),date(‘Y‘)));
                    $ex_where .= ‘ and dt >= ‘ . strtotime($time_start) . ‘ and dt <= ‘ . strtotime($time_end);
                    break;
                case 8://上季的数据
                    $season = ceil((date(‘n‘))/3) - 1;//当月是第几季度 
                    $time_start     = date(‘Y-m-d H:i:s‘, mktime(0, 0, 0,$season*3-3+1,1,date(‘Y‘)));                    
                    $time_end       = date(‘Y-m-d H:i:s‘, mktime(23,59,59,$season*3,date(‘t‘,mktime(0, 0 , 0,$season*3,1,date("Y"))),date(‘Y‘)));
                    $ex_where .= ‘ and dt >= ‘ . strtotime($time_start) . ‘ and dt <= ‘ . strtotime($time_end);
                    break;
                case 9://今年的数据
                    $time_start     = date("Y-m-d H:i:s",mktime(0, 0 , 0,1,1,date("Y")));                    
                    $time_end       = date("Y-m-d H:i:s",mktime(23,59,59,12,date(‘t‘),date("Y")));
                    $ex_where .= ‘ and dt >= ‘ . strtotime($time_start) . ‘ and dt <= ‘ . strtotime($time_end);
                    break;
                case 10://去年的数据
                    $time_start     = date("Y-m-d H:i:s",mktime(0, 0 , 0,1,1,date("Y") -1));                    
                    $time_end       = date("Y-m-d H:i:s",mktime(23,59,59,12,date(‘t‘),date("Y") -1));
                    $ex_where .= ‘ and dt >= ‘ . strtotime($time_start) . ‘ and dt <= ‘ . strtotime($time_end);
                    break;
                default://所有
                    break;
            }         
        }

 

php 打印今天,昨天,本周,上周,当月,上月,本季,上季,今年,去年数据