仅返回日期超过7天的行

问题描述 投票:0回答:1

我需要一些帮助。

我试图只返回mysql表中的行,其中今天的日期和'next_due'之间的差异是7天或更长。我到目前为止的代码是......

  $stmt = $conn->prepare("SELECT * FROM activities WHERE userId = ? AND status = ? ");
  $stmt->bind_param("ss", $userId, $status);
  $stmt->execute();
  $result = $stmt->get_result();
    if($result->num_rows === 0) echo "zero";
    else {
        while($row = mysqli_fetch_array($result)) {
          $activity_id          =   $row['id'];
          $title                =   $row['title'];
          $next_due             =   $row['next_due'];

          $next_due = strtotime($next_due);
          $next_due = date("d/m/Y", $next_due);
        }
      }

这将返回$ status设置为'open'的所有行,但我只想返回今天的日期和'next_due'中输入的日期之间的差异大于7天的那些行。

感谢帮助

date mysqli where
1个回答
0
投票

您可以研究一个名为datediff()的mysql函数。它返回两个日期之间的差异。

https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_datediff

© www.soinside.com 2019 - 2024. All rights reserved.