现在的位置: 网页制作教程网站制作教程 >正文
php网上学习

PHP根据开始日期和结束日期计算出周间隔

发表于2017/1/9 网站制作教程 0条评论 ⁄ 热度 2,401℃

已知开始日期和结束日期,php如何计算出间隔几周

如1:开始日期 2017-01-10,结束日期 2016-11-05时,PHP计算这个时间段的周间隔是多少,现提供一个方法:

/**
* 由开始时间的周日和结束时间的周日来求出间隔了多少周
* @author: phping
* @blog: phping.sinaapp.com
* @param string $start 开始日期的周日
* @param string $end 结束日期的周日
* @return int 间隔周数
*/
public static function getWeekIntervals($start,$end) {
$i = 0;
while (date("Y-m-d",strtotime($end) - 7 86400 * $i) > $start) {
$i++;
}
return $i;
}

上面函数返回间隔的周数。

  • 暂无评论