很容易与我的最爱
DateTime,
DateInterval和
DatePeriod
$start = new DateTime('2012-09-06');$end = new DateTime('2012-09-11');// otherwise the end date is excluded (bug?)$end->modify('+1 day');$interval = $end->diff($start);// total days$days = $interval->days;// create an iterateable period of date (P1D equates to 1 day)$period = new DatePeriod($start, new DateInterval('P1D'), $end);// best stored as array, so you can add more than one$holidays = array('2012-09-07');foreach($period as $dt) { $curr = $dt->format('D'); // substract if Saturday or Sunday if ($curr == 'Sat' || $curr == 'Sun') { $days--; } // (optional) for the updated question elseif (in_array($dt->format('Y-m-d'), $holidays)) { $days--; }}echo $days; // 4
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)