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

 

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>