码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2017-03-06 17:29:27      阅读:244      评论:0      收藏:0      [点我收藏+]

标签:bsp   break   art   class   where   cas   default   bre   数据   

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 打印今天,昨天,本周,上周,当月,上月,本季,上季,今年,去年数据

标签:bsp   break   art   class   where   cas   default   bre   数据   

原文地址:http://www.cnblogs.com/300js/p/6510859.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!