2011-12-28 15 views
1
date('Y-m-d', strtotime("last Monday")) 

現在の月曜日を表示します。最後の月曜日は月曜日です

どのように私は日付の例のためにこれを確認することができます。

2010-11-12と2011-03-04?

答えて

4

私はDateTimeクラスを使用します。

$dateTime = new DateTime('2010-11-12'); 
$dateTime->modify('last Monday'); 
echo $dateTime->format('Y-m-d'); 
2

DateTimeクラスas already answeredを使用するか、もう一度だけstrtotime­Docsを使用します。

echo date('Y-m-d', strtotime("last Monday", strtotime("2010-11-12"))); 

以上にきれいに並ん:

$date = strtotime("2010-11-12"); 
echo date('Y-m-d', strtotime("last Monday", $date)); 
2

のstrtotime関数は二通りのUNIXタイムスタンプを取ることができますが相対的な計算の今の時間として使用するための入力。ドキュメントを参照してくださいhere

関連する問題