Re: Week Days

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

 



On Thu, August 18, 2005 10:57 pm, benc11@xxxxxxxxx wrote:
> I am trying to add 3 (or a user-defined amount) week days to a certain
> date..
> An example is today 2005-08-18 then adding 3 week days to give me a
> date of
> 2005-08-23. I have tried searching online but cannot find an easy way
> of
> doing so.

Assuming you are willing to ignore holidays, which in most real-world
applications, you're not...

<?php
  $certain_date = '8/19/2005';
  $week_days = '...';
  list($m, $d, $y) = explode('/', $certain_date);
  $start = mktime(0, 0, 0, $m, $d, $y);
  //Every 5 days is a full week:
  $weeks = floor($week_days/5);
  $close = mktime(0, 0, 0, $m, $d + $weeks * 7, $y);
  $remainder = $week_days % 5;
  for ($added = 0, $day = 0; $added < $remainder; $day++){
    $dow = date('w', $close + $day*60*60*24); //Is it 'w' for 'day of
week'?
    if ($dow == 0 || $dow == 1){ //0|1 are Sun/Sat, right?
      $added++;
    }
  }
  $result = $close + $day * 60*60*24;
?>

-- 
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