Ack SORRY… slight bug fix: change the day of week line to read:
$dow = strtolower(date('l', time()+(($day-$today)*86400)));
I had user $unixmonth which is the timestamp of the beginning of the month so it looked into last month accidentally, so now it uses time() instead! Sorry again