primunuの日記

2008-03-17

現在の日にちが月の第何週目にあたるか出力する関数

| 00:19

PHPで現在の日にちが月の第何週目なのか出力する関数を、会社で頼まれたので作ってみた。

function getWeek(){
    $now = time();
    $saturday = 6;
    $week_day = 7;
    $w = intval(date('w',$now));
    $d = intval(date('d',$now));
    if ($w!=$saturday)$w = ($saturday - $w) + $d;
    return ceil($w/$week_day);
}

kjkj2010/12/21 14:33function getWeek(){
$now = time();
$saturday = 6;
$week_day = 7;
$w = intval(date('w',$now));
$d = intval(date('d',$now));
if ($w!=$saturday) {
$w = ($saturday - $w) + $d;
} else { // 土曜日の場合を修正
$w = $d;
}
return ceil($w/$week_day);
}