Re: Adding Business Days

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux