ある週の日付の違いを取得【php】

6004 ワード

直接コード:
function weekday($week)
{
    $year = substr($week, 0, 4);
    $week = substr($week, 4);


    $year_start = mktime(0, 0, 0, 1, 1, $year);

    $year_end = mktime(0, 0, 0, 12, 31, $year);

    $init = date("W", $year_start);
    $w = date("w", $year_start);

    $diff = intval($week) - intval($init);

    $tt = $year_start + $diff * 7 * 86400;
    //echo $year, "\t", $week, "\t", $init, "\t", $tt, "\t", $year_start,  PHP_EOL;

    $weekday['start'] = date("Y-m-d", $tt-$w * 86400);
    $weekday['end'] = date("Y-m-d", $tt+ (6-$w) * 86400);


    return $weekday;
}