Advertisement
cahyadsn

add bussiness day

Dec 29th, 2015
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.61 KB | None | 0 0
  1. <?php
  2.  function add_business_days($startdate,$buisnessdays,$holidays,$dateformat){
  3.   $i=1;
  4.   $dayx = strtotime($startdate);
  5.   while($i < $buisnessdays){
  6.    $day = date('N',$dayx);
  7.    $date = date('Y-m-d',$dayx);
  8.    if($day < 6 && !in_array($date,$holidays))$i++;
  9.    $dayx = strtotime($date.' +1 day');
  10.   }
  11.   return date($dateformat,$dayx);
  12.  }
  13.  
  14.  //Example 17days from 2015-12-29
  15.  date_default_timezone_set('Asia/Jakarta');
  16.  $startdate = '2015-12-29';
  17.  $holidays=array("2016-01-01");
  18.  echo '<p>Start date: '.date('r',strtotime( $startdate));
  19.  echo '<p>'.add_business_days($startdate,17,$holidays,'Y-m-d');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement