"); if($day < 31) { $ceiling = lastDay($month, $day, $year); } else { // no need to call function if it is 31st day of the month $ceiling = 31; } $firstdayT = date("D", mktime(0,0,0,$month,1,$year)); // textual $firstdayN = date("w", mktime(0,0,0,$month,1,$year)); // numeric // output the first day of the month for demonstration only print("The first numeric day of the month is 1 and falls on a $firstdayT ($firstdayN)"); $lastdayT = date("D", mktime(0,0,0,$month,$ceiling,$year)); // textual $lastdayN = date("w", mktime(0,0,0,$month,$ceiling,$year)); // numeric // output the last day of the month for demonstration only print("
The last numeric day of this month is $ceiling and falls on a $lastdayT ($lastdayN)"); /* loop to determine which week this is, count from 1st - last day of the month and increment week counter each time 6 (Sunday) is reached */ $checkme = $lastdayN; $week=1; for($i=1; $i < $ceiling; $i++) { if($checkme == 6) { $week++; $checkme=0; } else { // increase the day of the week $checkme++; } if($i == $day) { // it's today so escape the loop break; } } $day .= 'th'; print("

The $day day is in week #$week of this month"); ?>