PHPでの日付の加算・減算方法
週の対応もしています。
// 現在日付からの日付計算
echo "1日前 : " . date("Y/m/d", strtotime("-1 day")) . "<br/>";
echo "1ヶ月前 : " . date("Y/m/d", strtotime("-1 month")) . "<br/>";
echo "1年前 : " . date("Y/m/d", strtotime("-1 year")) . "<br/>";
echo "1週間前 : " . date("Y/m/d", strtotime("-1 week")) . "<br/>";
echo "1日後 : " . date("Y/m/d", strtotime("1 day")) . "<br/>";
echo "1ヶ月後 : " . date("Y/m/d", strtotime("1 month")) . "<br/>";
echo "1年後 : " . date("Y/m/d", strtotime("1 year")) . "<br/>";
echo "1週間後 : " . date("Y/m/d", strtotime("1 week")) . "<br/>";
// 指定日付からの日付計算
echo "1日前" . date("Y/m/d", strtotime("2010/07/20 -1 day")) . "<br/>";
echo "1ヶ月前" . date("Y/m/d", strtotime("2010/07/20 -1 month")) . "<br/>";
echo "1年前" . date("Y/m/d", strtotime("2010/07/20 -1 year")) . "<br/>";
echo "1週間前" . date("Y/m/d", strtotime("2010/07/20 -1 week")) . "<br/>";