• php 获取时间段


    switch ($type){
        case 'day'://当日
            $end=date('Y-m-d H:i:s',mktime(0,0,0,date('m'),date('d')+1,date('Y')));
            $where=' and '.$pre.'create_time>="'.date('Y-m-d').'" and '.$pre.'create_time<="'.$end.'"';
            break;
        case 'week'://获取周数据:往前推6天
            $week_start=date('Y-m-d H:i:s',mktime(0,0,0,date('m'),date('d')-6,date('Y')));
            $week_end=date('Y-m-d H:i:s',mktime(0,0,0,date('m'),date('d')+1,date('Y')));
            $where='and '.$pre.'create_time>="'.$week_start.'" and '.$pre.'create_time<="'.$week_end.'"';
            break;
        case 'week_now'://获取本周数据
            $week_now_start=date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("w")+1,date("Y")));
            $week_now_end=date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+7,date("Y")));
            $where='and '.$pre.'create_time>="'.$week_now_start.'" and '.$pre.'create_time<="'.$week_now_end.'"';
            break;
        case 'month'://获取月数据:往前推30天
            $month_start=date('Y-m-d H:i:s',mktime(0,0,0,date('m'),date('d')-29,date('Y')));
            $month_end=date('Y-m-d H:i:s',mktime(0,0,0,date('m'),date('d')+1,date('Y')));
            $where='and '.$pre.'create_time>="'.$month_start.'" and '.$pre.'create_time<="'.$month_end.'"';
            break;
        case 'month_now'://获取本月数据
            $month_now_start=date('Y-m-d H:i:s',mktime(0,0,0,date('m'),1,date('Y')));
            $month_now_end=date('Y-m-d H:i:s',mktime(23,59,59,date('m'),date('t'),date('Y')));
            $where='and '.$pre.'create_time>="'.$month_now_start.'" and '.$pre.'create_time<="'.$month_now_end.'"';
            break;
        case 'quarter_now'://获取本季度数据
            $season = ceil((date('n'))/3);//当月是第几季度
            $quarter_now_start=date('Y-m-d H:i:s',mktime(0, 0, 0,$season*3-3+1,1,date('Y')));
            $quarter_now_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')));
            $where='and '.$pre.'create_time>="'.$quarter_now_start.'" and '.$pre.'create_time<="'.$quarter_now_end.'"';
            break;
        case 'year_now'://获取本年数据
            $year_now_start=date('Y-01-01 00:00:00',time());
            $year_now_end=date('Y-12-31 23:59:59',time());
            $where='and '.$pre.'create_time>="'.$year_now_start.'" and '.$pre.'create_time<="'.$year_now_end.'"';
            break;
        case 'all'://获取今天之前的数据
            $all_end=date('Y-m-d 23:59:59',mktime(0,0,0,date('m'),date('d'),date('Y')));
            $where='and '.$pre.'create_time<="'.$all_end.'"';
            break;
    }
  • 相关阅读:
    2014第16周六
    2014第16周五
    2014第16周四
    2014第16周三CSS布局再学习摘录
    2014第16周二
    2014第16周一
    2014第15周日
    2014第15周六
    2014第15周五
    SDN:软件定义网络
  • 原文地址:https://www.cnblogs.com/zouke1220/p/8906517.html
Copyright © 2020-2023  润新知