Page 1 of 1
calculate first non-holiday in month
Posted: Mon May 28, 2007 5:24 am
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
Posted: Mon May 28, 2007 5:36 am
by volka
Are those the only two conditions:
Saturday -> +2 days
Sunday -> +1 day
?
Posted: Mon May 28, 2007 5:39 am
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 ?
Posted: Mon May 28, 2007 7:30 am
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.
Posted: Mon May 28, 2007 12:53 pm
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
, do something. I do not get any results for this if statement.
does anyone know why ???
cheers
juline
Posted: Mon May 28, 2007 1:15 pm
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
Posted: Mon May 28, 2007 1:21 pm
by juline
yeaaah, i jsut also figured out that the quotes are wrong set.
thanx to all.
problem solved.