没有周末的日差

没有周末的日差,第1张

没有周末的日差

很容易与我的最爱

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


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5427638.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-11
下一篇 2022-12-11

发表评论

登录后才能评论

评论列表(0条)

保存