PHP

PHPの日付計算

#今日の日付を取得(タイムスタンプ)
$date_today = mktime (0, 0, 0, date("m"), date("d"), date("y"));

#一週間前を取得
$date_oneweek = $date_today - 86400 * 7;

86400というのが一日を表しているらしいです。


本日から○日後の日付

echo "1日前" . date("Y/m/d",strtotime("-1 day"));
echo "1ヶ月前" . date("Y/m/d",strtotime("-1 month"));
echo "1年前" . date("Y/m/d",strtotime("-1 year"));
echo "1週間前" . date("Y/m/d",strtotime("-1 week"));

指定日付から○日後の日付が取得できます。

echo "1日前" . date("Y/m/d",strtotime("-1 day" ,strtotime("2005/12/10")));
echo "1ヶ月前" . date("Y/m/d",strtotime("-1 month" ,strtotime("2005/12/10")));
echo "1年前" . date("Y/m/d",strtotime("-1 year",strtotime("2005/12/10")));
echo "1週間前" . date("Y/m/d",strtotime("-1 week" ,strtotime("2005/12/10")));

参考:http://209.85.175.104/search?q=cache:I908YRvhUOYJ:www.ilovex.co.jp/Division/ITD/archives/2006/03/php.html+PHP%E3%80%80%E6%97%A5%E4%BB%98%E8%A8%88%E7%AE%97&hl=ja&ct=clnk&cd=1&gl=jp