You are here: Re: [PHP] Week Days « PHP « IT news, forums, messages
Re: [PHP] Week Days

Posted by Robert Cummings on 10/20/79 11:24

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. |
`------------------------------------------------------------'

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация