回答編集履歴

1

ed

2022/10/25 03:27

投稿

m.ts10806
m.ts10806

スコア80850

test CHANGED
@@ -1,3 +1,16 @@
1
+ > if(strtotime('-1 week', $target_date) && strtotime('-1 day', $target_date)){
2
+
3
+ 現状だと[strtotime()](https://www.php.net/manual/ja/function.strtotime.php)の処理結果を真偽(true/false)で確認しています。
4
+ 「システム日付との比較」が必要です。
5
+
6
+ ```PHP
7
+ if(strtotime('-1 week', $target_date) <= time() && strtotime('-1 day', $target_date) >= time() ){
8
+
9
+ ```
10
+ time()(現在のタイムスタンプ)が1週間前より大きく、1日前より小さい とする。
11
+
12
+ # 以下、要件捉え違いの回答
13
+
1
14
  forで1週間前(7日前)から1日ずつ。
2
15
  -1がでたら1日前
3
16
  ```PHP