Re: Week Days

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

 



On Fri, 2005-08-19 at 02:17, Robert Cummings wrote:
> This doesn't work since the value can be user defined and thus may span
> multiple weeks :) The following works but is dirty, I'm sure there's a
> better solution using modulus operator and adding and subtracting and a
> little voodoo... I'm just too lazy atm to think it up ;)

Ok so I felt like doing it :)

<?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);
while( $addWeekDays > 0 )
{
    $final += $daySeconds;

    $day = date( 'D', $final );
    if( $day != 'Sat' && $day != 'Sun' )
    {
        $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.          |
`------------------------------------------------------------'

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