Re: Suggestions?

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

 



I have a fiscal calendar table that I use for the same thing, storing the date, day of the week and a column indicating whether the day is a weekday, a weekend or a holiday. This allows me flexibility to also use the table to set business shutdowns as a holiday.

A simple date query can return the number of holidays/weekends to do the business day calculation.

Bastien

Sent from my iPod

On Jan 13, 2009, at 2:28 PM, "Dan Shirah" <mrsquash2@xxxxxxxxx> wrote:

On Tue, Jan 13, 2009 at 2:14 PM, <ceo@xxxxxxxxx> wrote:


Hard to say without knowing the data structures...

You can't do a simple count of the holidays and add that, because you might
end up with yet another holiday in the result.

Start at 12/23 and want to add 6 business days.

You find 1 holiday in between, so you add 7 business days and end up on New
Year's Day, a non-business day.

12/23
12/24
12/25 X
12/26
12/27
12/28
12/29
12/30
12/31
01/01 X

I think MySQL has built-in holiday / work day calculations, come to think
of it...

Exactly, ceo!

That's why I'm thinking of creating the array and then running a foreach()
loop on the array.

$day = date("w");

$today = date("m-d-Y");

if ($day == 4 || $day == 5) {
$two_day = mktime(0, 0, 0, date("m"), date("d")+4, date("Y"));
$two_day = date("m-d-Y", $two_day);
} else {
$two_day = mktime(0, 0, 0, date("m"), date("d")+2, date("Y"));
$two_day = date("m-d-Y", $two_day);
}

foreach ($holiday as $h) {
 if ($h >= $today && $h <= $two_day) {
$two_day = mktime(0, 0, 0, date("m", $two_day), date("d", $two_day)+1,
date("Y", $two_day));
   $two_day = date("m-d-Y", $two_day);
 }
}

That should add a day for each instance of a holiday that falls between the
dates, right?

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