码迷,mamicode.com
首页 > 其他好文 > 详细

获取月份

时间:2018-03-08 12:07:40      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:body   blog   exist   sub   []   turn   rto   desc   months   


/*年月+1算法 By Terry*/
function yearMonthAddOne($yearMonth){
$year = substr($yearMonth,0,4);
$month = substr($yearMonth,4);
if($month!=12){
$month = $month+1;
}else{
$year = $year+1;
$month = 1;
}
$month = $month<10?(‘0‘.$month):$month;
return $year.$month;
}

if(!function_exists(‘get_year_months_by_time_period‘)){

function get_year_months_by_time_period($start_time,$end_time=‘‘,$sort=‘asc‘){

$return = array();

$startYearMonth = date(‘Ym‘,strtotime($start_time));
$endYearMonth = $end_time?date(‘Ym‘,strtotime($end_time)):date(‘Ym‘);

$yearMonth = $startYearMonth;
$return[] = $yearMonth;
while ($yearMonth<$endYearMonth){

$yearMonth = yearMonthAddOne($yearMonth);
$return[] = $yearMonth;
}

if($sort==‘desc‘){
$return = array_reverse($return);
}

return $return;
}
}

获取月份

标签:body   blog   exist   sub   []   turn   rto   desc   months   

原文地址:https://www.cnblogs.com/php-linux/p/8527117.html

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