PHPでの日付時刻の計算についてまとめておきます。基本的に用いるのはstrtotimeとdateの2つです。 strtotimeは与えられた時刻のUnixタイムスタンプを返してくれる関数です。dateはUnixタイムスタンプを指定した形式に変換してくれる関数です。
<?php
//今日の日付を取得
date("Y-m-d", strtotime("now"));
//昨日、明日の日付を取得
date("Y-m-d", strtotime("-1 day"));
date("Y-m-d", strtotime("+1 day"));
//一週間前、一週間後の日付を取得
date("Y-m-d", strtotime("-1 week"));
date("Y-m-d", strtotime("+1 week"));
//一ヶ月前、一ヶ月後の日付を取得
date("Y-m-d", strtotime("-1 month"));
date("Y-m-d", strtotime("+1 month"));
//一年前、一年後の日付を取得
date("Y-m-d", strtotime("-1 year"));
date("Y-m-d", strtotime("+1 year"));
?>


