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

Posted 百里

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 打印今天,昨天,本周,上周,当月,上月,本季,上季,今年,去年数据的主要内容,如果未能解决你的问题,请参考以下文章

Oracle查询今天昨天本周上周本月上月数据

SQL语句获取当天,昨天,本周,上周,本月,上月的起始时间和结束时间

Sql Server中查询今天昨天本周上周本月上月数据

sql语句获取今天昨天近7天本周上周本月上月半年数据

用php获取本周,上周,本月,上月,本季度日期的代码

用php获取本周,上周,本月,上月,本季度日期的代码