I did a similar thing a while back using the below function. the key here is skipping the weekends, you can extend this to skip holidays as well.
Example:
Call the function - >
addDays(strtotime($startDate), 20, $skipdays,$skipdates = array())
<?php
function addDays($timestamp, $days, $skipdays = array("Saturday", "Sunday"), $skipdates = NULL) {
// $skipdays: array (Monday-Sunday) eg. array("Saturday","Sunday")
// $skipdates: array (YYYY-mm-dd) eg. array("2012-05-02","2015-08-01");
//timestamp is strtotime of ur $startDate
$i = 1;
while ($days >= $i) {
$timestamp = strtotime("+1 day", $timestamp);
if ( (in_array(date("l", $timestamp), $skipdays)) || (in_array(date("Y-m-d", $timestamp), $skipdates)) )
{
$days++;
}
$i++;
}
return $timestamp;
//return date("m/d/Y",$timestamp);
}
?>
[Edit] : Just read an amazing article on nettuts, Hope this helps http://net.tutsplus.com/tutorials/php/dates-and-time-the-oop-way/
0 Comments