|
Posted by Robert Cummings on 10/20/79 11:24
On Sat, 2005-08-20 at 03:15, benc11@gmail.com wrote:
> Rob,
>
> I tried your code below, but it didn't work. I put the number of week days
> in $addWeekdays variable. Am I doing something wrong or is there an error in
> the code? Appreciate your help!
There's an error... I didn't account for the starting day being a
weekend day :) The following should work (somewhat tested) and I also
removed locale dependency from it (check for "Sat" and "Sun").
<?php
//
// For every 5 days to add we wrap a week and are right back where we
// started so...
//
$addWeekdays = isset( $argv[1] ) ? $argv[1] : 0; // command line for fun
$start = time();
$addWeeks = (int)($addWeekdays / 5);
$addWeekDays = ($addWeekdays % 5);
$daySeconds = (24 * 60 * 60);
$final = $start + ($addWeeks * 7 * $daySeconds);
$day = date( 'w', $final );
if( $day == 1 ) // Saturday
{
$final += ($daySeconds * 2);
}
else
if( $day == 0 ) // Sunday
{
$final += $daySeconds;
}
else
{
while( $addWeekDays > 0 )
{
$final += $daySeconds;
$day = date( 'w', $final );
if( $day != '0' && $day != '6' )
{
$addWeekDays--;
}
}
}
echo 'Start: '.date( 'Y-m-d (D)', $start )."\n";
echo 'Final: '.date( 'Y-m-d (D)', $final )."\n";
--
..------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'
Navigation:
[Reply to this message]
|