Re: Adding Business Days
| From: | Richard Lynch | Date: | Fri, 11 Feb 2005 16:52:00 +0000 |
| Subject: | Re: Adding Business Days | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-208536@lists.php.net to get a copy of this message | ||
Ben C wrote:
> I am trying to add 5 business/week days to today's date. Does anyone
> know a good way of how to do it?
Untested Code:
<?php
//Start with a time-tick NOW:
$now = mktime();
echo "Starting on ", date('l m/d/Y', $now), "<br />\n";
$mdy = date('m/d/Y', $now);
list($m, $d, $y) = explode($mdy);
$workdays = 0;
$then = $now;
while ($workdays < 5){
$then += 60 * 60 * 24; //24 hours, one day
$dow = date('w', $then); //Day Of Week (dow)
if ($dow != 0 && $dow != 6){ //0 Sun ; 6 Sat
$workdays++;
}
}
echo "$workdays away: ", date('l m/d/Y', $then), "<br />\n";
?>
--
Like Music?
http://l-i-e.com/artists.htm