LoginSignup
0
0

More than 3 years have passed since last update.

PHPで指定日付前を取得する

Posted at

はじめに

調べる機会がありましたので、備考録としてまとめました。
日付取得で使用する関数はdate関数strtotime関数である。

取得方法

date("Ymd", strtotime("-1 day")); //現在日より1日前を取得
date("Ymd", strtotime("-1 week")); //現在日より1週間前を取得
date("Ymd", strtotime("-1 month")); //現在日より1ヶ月前を取得
date("Ymd", strtotime("-1 year")); //現在日より1年前を取得
date("Ymd", strtotime('last Saturday')); //現在日より先週の日曜日の日付を取得
date("Ymd", strtotime("-1 day" ,strtotime("20210211"))); //2021年2月11日より1日前を取得

※指定日付後を取得したい場合は、上記サンプルコードのマイナスを消す。

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0