zerogo

计算一段日期内的周末天数(星期六,星期日总和

function get_weekend_days($start_date,$end_date){
if (strtotime($start_date) > strtotime($end_date)) list($start_date, $end_date) = array($end_date, $start_date);
$start_reduce = $end_add = 0;
$start_N = date(\'N\',strtotime($start_date));
$start_reduce = ($start_N == 7) ? 1 : 0;
$end_N = date(\'N\',strtotime($end_date));
in_array($end_N,array(6,7)) && $end_add = ($end_N == 7) ? 2 : 1;
$days = abs(strtotime($end_date) - strtotime($start_date))/86400 + 1;
return floor(($days + $start_N - 1 - $end_N) / 7) * 2 - $start_reduce + $end_add;
}

echo get_weekend_days(date("Y-m-d H:i:s",time()),"2011-8-21 15:23:48");

原文地址:http://www.corange.cn/archives/2011/08/3782.html
发表于 2011-08-29 08:58  corange  阅读(262)  评论(0编辑  收藏  举报
 

分类:

技术点:

相关文章:

  • 2021-11-05
  • 2021-11-05
  • 2021-12-13
  • 2021-08-05
  • 2021-11-27
  • 2021-12-15
  • 2021-12-26
猜你喜欢
  • 2021-08-31
  • 2021-04-09
  • 2021-12-17
  • 2021-10-06
  • 2021-11-18
  • 2021-11-05
  • 2021-11-05
相关资源
相似解决方案