指定日から特定の日時を取得する
$date = strtotime('2020-01-22 16:00:00');
// 2020/01/22 16時から30秒前
echo date('Y-m-d H:i:s', strtotime('-30 sec', $date)); // 2020-01-22 15:59:30
// 2020/01/22 16時から10分前
echo date('Y-m-d H:i:s', strtotime('-10 min', $date)); // 2020-01-22 15:50:00
// 2020/01/22 16時から3時間前
echo date('Y-m-d H:i:s', strtotime('-3 hour', $date)); // 2020-01-22 13:00:00
// 2020/01/22 16時から1週間前
echo date('Y-m-d H:i:s', strtotime('-1 week', $date)); // 2020-01-15 16:00:00
// 2020/01/22 16時から7日前
echo date('Y-m-d H:i:s', strtotime('-7 day', $date)); // 2020-01-15 16:00:00
// 2020/01/22 16時から3か月後
echo date('Y-m-d H:i:s', strtotime('+3 month', $date)); // 2020-04-22 16:00:00
// 2020/01/22 16時から1年前
echo date('Y-m-d H:i:s', strtotime('-1 year', $date)); // 2019-01-22 16:00:00
-----------------
現在時間から特定の日時を取得
※time()はつけなくてもよい
// 30秒前
echo date("Y-m-d H:i:s", strtotime("-30 sec")); // 30秒前
// 10分前
echo date("Y-m-d H:i:s", strtotime("-10 min")); // 10分前
// 1時間前
echo date('Y-m-d H:i:s', strtotime('-1 hour', time()));
// 1週間前
echo date('Y-m-d H:i:s', strtotime('-1 week', time()));
// 7日後
echo date('Y-m-d H:i:s', strtotime('+7 day', time()));
// 7日前
echo date('Y-m-d H:i:s', strtotime('-7 day', time()));
// 3か月後
echo date('Y-m-d H:i:s', strtotime('+3 month'));
// 3か月前
echo date('Y-m-d H:i:s', strtotime('-3 month'));
// 1年後
echo date('Y-m-d H:i:s', strtotime('+1 year'));
// 1年前
echo date('Y-m-d H:i:s', strtotime('-1 year'));
$date = strtotime('2020-01-22 16:00:00');
// 2020/01/22 16時から30秒前
echo date('Y-m-d H:i:s', strtotime('-30 sec', $date)); // 2020-01-22 15:59:30
// 2020/01/22 16時から10分前
echo date('Y-m-d H:i:s', strtotime('-10 min', $date)); // 2020-01-22 15:50:00
// 2020/01/22 16時から3時間前
echo date('Y-m-d H:i:s', strtotime('-3 hour', $date)); // 2020-01-22 13:00:00
// 2020/01/22 16時から1週間前
echo date('Y-m-d H:i:s', strtotime('-1 week', $date)); // 2020-01-15 16:00:00
// 2020/01/22 16時から7日前
echo date('Y-m-d H:i:s', strtotime('-7 day', $date)); // 2020-01-15 16:00:00
// 2020/01/22 16時から3か月後
echo date('Y-m-d H:i:s', strtotime('+3 month', $date)); // 2020-04-22 16:00:00
// 2020/01/22 16時から1年前
echo date('Y-m-d H:i:s', strtotime('-1 year', $date)); // 2019-01-22 16:00:00
-----------------
現在時間から特定の日時を取得
※time()はつけなくてもよい
// 30秒前
echo date("Y-m-d H:i:s", strtotime("-30 sec")); // 30秒前
// 10分前
echo date("Y-m-d H:i:s", strtotime("-10 min")); // 10分前
// 1時間前
echo date('Y-m-d H:i:s', strtotime('-1 hour', time()));
// 1週間前
echo date('Y-m-d H:i:s', strtotime('-1 week', time()));
// 7日後
echo date('Y-m-d H:i:s', strtotime('+7 day', time()));
// 7日前
echo date('Y-m-d H:i:s', strtotime('-7 day', time()));
// 3か月後
echo date('Y-m-d H:i:s', strtotime('+3 month'));
// 3か月前
echo date('Y-m-d H:i:s', strtotime('-3 month'));
// 1年後
echo date('Y-m-d H:i:s', strtotime('+1 year'));
// 1年前
echo date('Y-m-d H:i:s', strtotime('-1 year'));