|
Posted by "Richard Lynch" on 10/20/45 11:24
On Thu, August 18, 2005 10:57 pm, benc11@gmail.com 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
[Back to original message]
|