I've been trying to get the code below to work, and while it worked with June it is not working with July.
The below results in a value of 3 for $first_day_of_month when it should be 2 for Tuesday.
$date = strtotime('20140702'); // July 02, 2014
$month = date('m',$date);
$year = date('Y',$date);
$days_in_month = date('t',$date);
$first_day_of_month = date('w', strtotime($year . $month . 01)); // sunday = 0, saturday = 6