php上月下月时间获取

来源:互联网 发布:冰川网络珍宝阁 编辑:程序博客网 时间:2024/06/11 19:43

这个在后台做统计查询的时候用的到,这次是财务妹子让我加的,其实也就是利用php自带的函数就能实现了,感觉不错:

           if($pre_month && $pre_month == 1 && $start_date && $end_date ){           $timestamp=strtotime($start_date);           $start_date=date('Y-m-01',strtotime(date('Y',$timestamp).'-'.(date('m',$timestamp)-1).'-01'));           $end_date=date('Y-m-d',strtotime("$start_date +1 month -1 day"));     }

查询下个月时间:

if($next_month && $next_month == 1 && $start_date && $end_date ){         $time_arr =   $this->getNextMonthDays($start_date);           $start_date=$time_arr[0];           $end_date=$time_arr[1];       }private  function getNextMonthDays($date){    $timestamp=strtotime($date);    $arr=getdate($timestamp);    if($arr['mon'] == 12){        $year=$arr['year'] +1;        $month=$arr['mon'] -11;        $firstday=$year.'-0'.$month.'-01';        $lastday=date('Y-m-d',strtotime("$firstday +1 month -1 day"));    }else{        $firstday=date('Y-m-01',strtotime(date('Y',$timestamp).'-'.(date('m',$timestamp)+1).'-01'));        $lastday=date('Y-m-d',strtotime("$firstday +1 month -1 day"));    }    return array($firstday,$lastday);}

复制进去直接就能用,这样感觉果然爽多了。

阅读全文
0 0
原创粉丝点击