[PHP] ÇØ´ç ÁÖ(week)ÀÇ ³¯Â¥ ã±â
## find a day of the n'th week in month
## $n = 1'th week, 2nd week, . n'th week
## $w = Sunday(0), Monday(1), ... Saturday(6)
## default) find a day of the first week of sunday in this month
##
function day_of_week_in_month($n=1, $w=0, $month=0, $year=0)
{
if($n < 1) $n = 1;
if($w<0 || $w>6) $w = 0;
if(!$month) $month = date('m');
if(!$year) $year = date('Y');
$week = date('w',mktime(1,0,0,$month,1,$year));
$sunday = ($week==0) ? 1 : (8-$week); // day of first sunday
$day = ($sunday+$w) + ($n-1)*7;
return $day;
}
echo day_of_week_in_month(2,1); // ÇöÀç´ÞÀÇ µÎ¹ø°ÁÖ ¿ù(1)¿äÀÏÀº ¸çÄ¥?
|