I am trying to add 2 weekdays to a date, but I also want to exclude the days in an array.
array of dates to exclude:
$bankHolidays = array();
foreach($obj as $e) {
if($e->division == 'england-and-wales') {
foreach($e->events as $events) {
$bankHolidays[] = $events->date;
}
}
}
Adding 2 working days to date
$ret = date('d-m-Y', strtotime($bill["charge_customer_at"]. ' +2 weekdays'));
How can I include the array of dates to exclude?
As an example, if my date was 2017-07-19
and i want to add 2 week days, that would output 2017-07-21
.
But if 2017-07-21
was in my array, it should skip this date and continue adding 2 weekdays so the output would end up being 2017-07-24
because of the weekend as well.
Select a blank cell and type this formula =WORKDAY(A2,B2), and press Enter key to get result. Tip: In the formula, A2 is the start date, B2 is the days you want to add. Now the end date which add 45 business days excluding weekends has been shown.
The NETWORKDAYS function in Excel returns the number of workdays between two dates, excluding weekends and, optionally, the holidays you specify. The first two arguments are obligatory and the third one is optional: Start_date - initial date from which to start counting working days.
You could do something as simple as use a while
loop.
$date = '2017-07-25';
$reserved = ['2017-07-27', '2017-07-28'];
$days = 2;
while ($days > 0) {
$date = date('Y-m-d', strtotime($date . ' +1 weekday'));
if (! in_array($date, $reserved)) $days--;
}
var_dump($date);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With