выведет третью пятницу девятого месяца, с другими, думаю, разберешься, дни посчитаешь, несложно будет.
А вообще я это не писал, просто иногда надо заглядывать в мануал и читать раздел Date and Time functions.
До нас уже давно все написано.
echo nthDayOfMonth(3,5,9,2003);
/* dayofweek() will return the day of the week a given date falls. 0=Sunday, 1=Monday, etc. */
function dayofweek($day,$month,$year) {
/* Check date for validity */
if (!checkdate($month,$day,$year))
return -1;
$a=(int)((14-$month) / 12);
$y=$year-$a;
$m=$month + (12*$a) - 2;
$retval=($day + $y + (int)($y/4) - (int)($y/100) + (int)($y/400) + (int)((31*$m)/12)) % 7;
return $retval;
}
/* phpdow_mod is a mod function that deals with negative numbers properly, used by the nthDayOfMonth function below. */
function phpdow_mod($a,$b) {
if ($a <= 0)
return (int)phpdow_mod($b-abs($a),$b);
else
return (int)($a%$b);
}
/*
* nthDayOfMonth($n,$dow,$month,$year) will compute the Nth day of the given
* month. For example, the first Monday in April 2001.
*
* Parameters:
* $n - the Nth day you want, i.e. 2 for 2nd
* $dow - The day of week you want, 0=Sunday, 1=Monday, etc. [0-6]
* $month - The month you want [1-12]
* $year - The full year [like 2001]
*
* Returns:
* The date, in the month you passed, that fits the criteria.
* or..
* -1 = invalid date
* -2 = There is no Nth day of that month, like no 5th Tuesday
* of the specified month
*/
function nthDayOfMonth($n,$dow,$month,$year) {
/* Check the date */
if ($month > 12)
return -1;
if ($dow > 6)
return -1;
/* Valid Nth day, should be no more than 5 */
if (($n <= 0) || ($n > 5))
return -1;
$retval = (7*$n)-6+phpdow_mod($dow-dayofweek(1,$month,$year),7);
/* Sanity check */
if (!checkdate($month,$retval,$year))
return -2;
return $retval;
}
?>