Created
July 2, 2020 13:46
-
-
Save z2z/f35a5750063c92c2ea76b2011f7de526 to your computer and use it in GitHub Desktop.
business date add exclude holiday php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# $date must be in YYYY-MM-DD format | |
# You can pass in either an array of holidays in YYYY-MM-DD format | |
function addBusinessDays($date,$numDays=1,$holidays='') { | |
$addDay = 0; | |
while ($numDays--) { | |
while (true) { | |
$addDay++; | |
$newDate = date('Y-m-d', strtotime("$date +$addDay Days")); | |
$newDayOfWeek = date('w', strtotime($newDate)); | |
if ( $newDayOfWeek>0 && $newDayOfWeek<6 && !in_array($newDate,$holidays)) break; | |
} | |
} | |
return $newDate; | |
} | |
echo addBusinessDays('2020-07-02',20,['2020-07-03','2020-07-06']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment