Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
日付から7年を減算しようとしています...
私はこれを試しましたが、うまくいきませんでした:(何が間違っているのですか?
strtotime("-7 year", strtotime(date("Y")))
1131498720これは私が探している答えをエコーアウトします2005
1131498720
2005
「-7」は変数であることを忘れました$x = -7
$x = -7
strtotimeは、UNIXタイムスタンプ(1970年1月からの秒数)を返します。1131498720は、7年前の2005年11月8日に対応します。
あなたは何年も差し引いているだけなので、単純に
$seven_years_ago = date('Y') - 7;
試す:
$str = date('Y', strtotime(date('Y') . " -7year")); echo $str;
デモ