calculate first non-holiday in month

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
juline
Forum Commoner
Posts: 37
Joined: Thu Jul 15, 2004 9:05 am

calculate first non-holiday in month

Post by juline »

hi guys,

i am having following problem. i need to claculate starting from a given date the next month's first non holiday day. means e.g. i have the date 2007-11-01 --> the value i want to get would be 2007-12-03 - would be a monday, 2007-12-01 would be wrong.

does anyone have an idea how to realize that?

cheers
juline
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Are those the only two conditions:
Saturday -> +2 days
Sunday -> +1 day
?
juline
Forum Commoner
Posts: 37
Joined: Thu Jul 15, 2004 9:05 am

Post by juline »

hi volka,

actually not. but they are the most important and frequently ones. well there are more holidays ofcourse. is there a way to put the known non sat or sun days in a kind of ressource so the next day will be calculated ?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Well... If you're going to calculate it using holidays AND weekends, then you could just... store the holidays you consider valid in a database and check if that entry exists in the database before using it. As for weekends... PHP's date() function will give you the day of the week.

Just kind of increment the day, check the database, and check the day of the week. If it fails the checks, go to the next day.
juline
Forum Commoner
Posts: 37
Joined: Thu Jul 15, 2004 9:05 am

Post by juline »

first of all thanx for helping guys,

i found following solution by googling on other forums:

first i calculate the holidays as following:

e.g. Whitsunday -->

Code: Select all

$Whitsunday = date('d.m.Y', mktime(0,0,0, date ('m', easter_date($row[0])), date('d', easter_date($row[0]))+49, date('Y', easter_date($row[0]))));
or a static one like All Saints' Day -->

Code: Select all

$allsaintsday = date("d.m.Y", mktime(0,0,0,11,1, $row[0]));
etc..

then i check the date if it is a weekend day. if sunday i add 1 day, if saturday i add 2 days.

After this i want to check if the date is one of the holidays i allready have calculated on top --- and here my problem starts:

i am checking like this

Code: Select all

if ($date == '$allsaintsday')
, do something. I do not get any results for this if statement.

does anyone know why ???

cheers
juline
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

You can't put a PHP variable in single quotes. You're counting it as a literal string.

BTW, I didn't know there was an easter_date() function. Everyday, something new. :-p
juline
Forum Commoner
Posts: 37
Joined: Thu Jul 15, 2004 9:05 am

Post by juline »

yeaaah, i jsut also figured out that the quotes are wrong set.
thanx to all.

problem solved.
Post Reply