时间计算
1、时间差
一、月份
①
$start = new DateTime('2018-11-20');
$end = new DateTime('2019-11-15');
$diff = $start->diff($end);
$diff_month = $diff->format('%y')*12+$diff->format('%m');
echo $diff_month;
②
function getMonthNum($date1,$date2){
$date1_stamp=strtotime($date1);
$date2_stamp=strtotime($date2);
list($date_1['y'],$date_1['m'])=explode("-",date('Y-m',$date1_stamp));
list($date_2['y'],$date_2['m'])=explode("-",date('Y-m',$date2_stamp));
return abs($date_1['y']-$date_2['y'])*12 +$date_2['m']-$date_1['m'];
}
echo getMonthNum('2018-11-20','2019-11-15');
二、、天数
$datetime_start = new DateTime('2018-11-20');
$datetime_end = new DateTime('2019-10-15');
$diff = $datetime_start->diff($datetime_end);
$service_cycle = $datetime_start->diff($datetime_end)->days;
echo $service_cycle;

浙公网安备 33010602011771号