2017-01-01 5 views
0
私はこのように1969年までに開始する実際の週番号を取得する必要があります

1969で始まる週の数を取得します:あなたが見ることができるようにPHP:年

$dateTime = new DateTime; 
$now = '2017-01-01'; 

// 
// $week = date('W', strtotime($now . ' +2 days')); 
// I will get the week number between 01-53 and this is not what I want. 
// I need to set the starting year and get the week number since 1969 to get the expected results. 
// How to get the value 2506 from this $week variable? 
// 

$dateTime->setISODate('1969', 2506, -1); 
$start_by = $dateTime->format('Y-m-d'); 

// output: 2016-12-31 

は、「2016年12月31日は」日時です私の週の開始。

ありがとうございます!

+0

は** **実際の週番号とは何ですか?今年の週番号ですか?それは1969年以来の数週間ですか?これは宿題ですか? – Peon

+0

1969年以来の週数です。 –

+0

現在の週番号を取得し、すべての前年度の週の番号でそれを掛けます。今週の週は23、次に23 +(1969 * 53)=ある値 –

答えて

3

簡単なようだ、

<?php 
    $date1 = new DateTime(); 
    $date2 = new DateTime("1969-01-21"); 
    $interval = $date1->diff($date2); 

    echo ceil($interval->days/7); 
?> 
+0

あなたは私の人生、男を救う! –