Determining the first business day of any given month in PHP
For an automated script we needed to calculate the first business day of the month. That turned out to be somewhat of a challenge. Here’s the code we came up with: (Inspired by Gledison’s last business day of the week!)
function FirstBusinessDay($year, $month, $day)
{
$today = "$year-$month-$day";
$fbday = 1;
$wday = date("N",strtotime("$year-$month-$fbday"));
if ($wday == 6) $fbday += 2; // saturday?
if ($wday == 7) $fbday += 1; // sunday?
$fbday = date("Y-m-d",strtotime("$year-$month-$fbday"));
if ($fbday == $today) {
return true;
} else {
return false;
}
}
Categories
- Food (2)
- Humor (1)
- Inspirational (2)
- Music (1)
- Photography (2)
- Programming (1)
Twitter feed
- Hoogtevrees? Het zijn niet zozeer de hoogtes waar ik bang voor ben. Het gaat meer om het vallen.2012/02/23 10:14
- Just found out that CTRL-SHIFT in Windows makes your keyboard mix up all the special characters. Who comes up with "features" like these?!2012/02/21 13:54
- Led Zep in the mix on #bassdrive2012/02/21 10:41
- Rutger van Castricum heeft het moeilijk in de wereld draait door #dwdd
http://t.co/ebOl6TLw2012/02/21 08:02 - Als je in de fik staat, doe dan een stap opzij2012/02/20 20:42
- Hoogtevrees? Het zijn niet zozeer de hoogtes waar ik bang voor ben. Het gaat meer om het vallen.





