I need a method for adding \"business days\" in PHP. For example, Friday 12/5 + 3 business days = Wednesday 12/10.
At a minimum I need the code to understand weekend
Variant 1:
0) {
$timestamp += 86400;
if (date('N', $timestamp)<6) $bDays--;
}
return $timestamp;
}
Variant 2:
0) {
$timestamp += 86400;
if (date('N', $timestamp)<6) $bDays--;
}
return $timestamp;
}
Variant 3:
0) {
$timestamp += 86400;
if (date('N', $timestamp)<6) $bDays--;
}
return $timestamp += 86400;
}
The additional holiday considerations can be made using variations of the above by doing the following. Note! assure all the timestamps are the same time of the day (i.e. midnight).
Make an array of holiday dates (as unixtimestamps) i.e.:
$holidays = array_flip(strtotime('2011-01-01'),strtotime('2011-12-25'));
Modify line :
if (date('N', $timestamp)<6) $bDays--;
to be :
if (date('N', $timestamp)<6 && !isset($holidays[$timestamp])) $bDays--;
Done!
0) {
$timestamp += 86400;
if (date('N', $timestamp)<6 && !isset($holidays[$timestamp])) $bDays--;
}
return $timestamp;
}