php计算给定时间段内一共有多少周,支持跨年计算

2019-09-25  本文已影响0人  coffeys
function computeWeek($date1,$date2){
    $diff = abs(strtotime($date2) - strtotime($date1));    #取差集的绝对值
    $week = floor($diff/(24*60*60*7));                    #获取多少周
    $day = ($diff%(24*60*60*7))/(24*60*60);                #除周数以外的天数
    $res = $week."周又".($day+1)."天";
    return $res;
}
echo computeWeek("2011-06-06","2012-06-06")."<br>";    #52周又3天
echo computeWeek("2012-06-09","2012-06-01")."<br>";    #1周又2天
上一篇下一篇

猜你喜欢

热点阅读