Blogger Information
Blog 1
fans 0
comment 0
visits 947
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
获取两个时间点之间的间隔月份
棒槌的博客
Original
949 people have browsed it
<?php
function translateTimr($begin,$end){
   $brr = explode('-',$begin);
   $err = explode('-',$end);
   $arr = [];
   if($err[0]-$brr[0] == 0)
   {
       $num = $err[1]-$brr[1]+1;
   }else if($err[0]-$brr[0] == 1){
       $num = 12-$brr[1]+1+$err[1];
   }else{
       $num = 12*($err[0]-$brr[0])-$brr[1]+$err[1];
   }

   if($brr[0] == $err[0] && $brr[1] == $err[1])
   {
       $days = date('t', strtotime($begin));
       for($i = 1 ; $i <= $days ; $i++)
       {
           if(strtotime($begin.'-'.$i) == strtotime(date('Y-m-d',time()))){
               break;
           }
           array_push($arr,$begin.'-'.$i);
       }
   }else{
       for($i = 0 ; $i < $num; $i++)
       {
           $month = date('m',strtotime($begin));
           $year = date('Y',strtotime($begin));
           $month = $month+$i;
           if($month > 12)
           {
               if($month%12 == 0)
               {
                   $year = $year + floor($month/12-1)*1;
                   $month = $month-12*(floor($month/12)-1);
               }else{
                   $year = $year + floor($month/12)*1;
                   $month = $month-12*floor($month/12);
               }

           }
           array_push($arr,$year.'-'.$month);
       }
   }
   return $arr;
}
?>


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post