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")));